How to Bind to Property Which Resides in the App Xaml backend

后端 未结 3 1065
猫巷女王i
猫巷女王i 2020-12-29 13:15

I have a Property in my App.xaml.cs called User that holds the User details. I have read here that you can\'t have a dependency property on the App

相关标签:
3条回答
  • 2020-12-29 14:00

    And to access it programatically in C# you can do this:

    ((App)Application.Current).YourMethod
    ((App)Application.Current).YourProperty
    
    0 讨论(0)
  • 2020-12-29 14:03

    I have read here that you can't have a dependency property on the App class.

    Indeed you can't, because Application doesn't inherit from DependencyObject. However, it's not necessary : only the target property of a binding needs to be a dependency property.

    If you want to bind to a property of your App class, you can do it like that :

    IsEnabled="{Binding Path=User, Source={x:Static Application.Current}}"
    
    0 讨论(0)
  • 2020-12-29 14:18

    You can bind declaratively in Silverlight to Application.Current by using a custom converter.

    See my blog post here

    0 讨论(0)
提交回复
热议问题