I have to follow the ProgressIndicator
<MahAppsControls:ProgressIndicator Width="100" Height="10" VerticalAlignment="Center" ProgressColour="White" Visibility="{Binding ProgressVisibility}"/>
and in the ViewModel connected to this view I implements
private Visibility progressVisibility = Visibility.Collapsed; public Visibility ProgressVisibility { get { return progressVisibility; } set { if (value == progressVisibility) return; progressVisibility = value; this.OnPropertyChanged("ProgressVisibility"); } }
The problem is that this binding fails, and I don't know why. With Snoop, I have
System.Windows.Data error: 40: BindingExpression path error: the 'ProgressVisibility' property was not found on the 'object' '' ProgressIndicator '(Name =' progressIndicator ')'. BindingExpression: Path = ProgressVisibility; DataItem = 'ProgressIndicator' (Name = 'progressIndicator');
target element is 'ProgressIndicator' (Name = 'progressIndicator'); target property - "Visibility" (type "Visibility") System.Windows.Data error: 40: BindingExpression path error: the 'ProgressVisibility' property was not found on the 'object' '' ProgressIndicator '(Name =' progressIndicator ')'. BindingExpression: Path = ProgressVisibility; DataItem = 'ProgressIndicator' (Name = 'progressIndicator');
target element is 'ProgressIndicator' (Name = 'progressIndicator'); target property - "Visibility" (type "Visibility") System.Windows.Data error: 40: BindingExpression path error: the 'ProgressVisibility' property was not found on the 'object' '' ProgressIndicator '(Name =' progressIndicator ')'. BindingExpression: Path = ProgressVisibility; DataItem = 'ProgressIndicator' (Name = 'progressIndicator');
target element is 'ProgressIndicator' (Name = 'progressIndicator'); target is "Visibility" (type "Visibility")
I appreciate that there is a binding error, but I set the main DataContext window in App.xaml.cs via
MainWindow window = new MainWindow(); MainWindowViewModel mainWindowViewModel = new MainWindowViewModel(); // When the ViewModel asks to be closed, close the window. EventHandler handler = null; handler = delegate { mainWindowViewModel.RequestClose -= handler; window.Close(); }; mainWindowViewModel.RequestClose += handler; // Allow all controls in the window to bind to the ViewModel by setting the // DataContext, which propagates down the element tree. window.DataContext = mainWindowViewModel; window.Show();
So, why is the binding error?
Thank you for your time.
c # wpf binding mahapps.metro
Moonknight
source share