I have been working on a C# 4.0 WPF project and need to figure out how to databind a Boolean value. I have a reference to my Application.Current object in a window. My “App” object contains a boolean field called “Downloaded” that is true if the user has downloaded information from a web service. I need to databind a textbox’s IsEnabled field to this Downloaded value. Any tips? Here is what I have come up with so far. (Any useful links to better learn WPF XAML are greatly appreciated!)
C# code:
class MainWindow : Window
{
private App MyApp = App.Current as App;
}
XAML:
<TextBox ... IsEnabled="{Binding Source=MyApp, Path=Downloaded}" />
WPF can’t resolve that Source. If you’re specifying a Source in XAML, it will typically be a resource elsewhere in the XAML (e.g. an ObjectDataProvider). MyApp is actually a path from your Window object, not a source in itself.
What you probably want is a multipart path:
However, you’ll still have a few problems with this:
Note also you must implement INotifyPropertyChanged on your App class, and raise PropertyChanged for the Downloaded property.