I'm writing a WPF application and my problem is that I have a class member bound with the property "IsEnabled" of one element of xaml and basically the binding seems not to work at all.
Here some extracts of my code:
XAML
<Window.Resources>
<Style TargetType="{x:Type DockPanel}" x:Key="MyDockPanel">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Gray"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<DockPanel x:Name="home_dock_panel" Style="{StaticResource MyDockPanel}" HorizontalAlignment="Left" Height="35" LastChildFill="False" Margin="22,82,0,0" VerticalAlignment="Top" Width="189" MouseDown="GoToHome" IsEnabled="{Binding Path=UnlockMenu}">
<Image Source="images/home.png" Height="26" RenderTransformOrigin="1.277,0.518" Margin="0,5,0,4.2"/>
<Label Content="Home" Height="35" VerticalAlignment="Top" Foreground="White" FontSize="20" FontWeight="Bold"/>
</DockPanel>
Here the function that allows changing page
private void GoToXPage(object sender, MouseButtonEventArgs e)
{
if(central_frame.Content.GetType() != typeof(LathePage))
{
ViewModel viewModel = new ViewModel();
central_frame.Content = new XPage(viewModel);
panel_dock.DataContext = viewModel;
}
Here a part of ViewModel code
public class ViewModel : INotifyPropertyChanged
{
public GenerateCommand Generate { get; set; }
public bool UnlockMenu { get; set; }
public ViewModel()
{
Generate = new GenerateCommand();
Generate.PropertyChanged += InnerPropertyChanged;
UnlockMenu = Generate.UnlockMenu;
}
private void InnerPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(e.PropertyName == "UnlockMenu")
{
UnlockMenu = Generate.UnlockMenu;
NotifyPropertyChanged("UnlockMenu");
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
In the class GenerateCommand I call NotifyPropertyChanged("UnlockMenu").
Does anyone have some suggestions on this problem?