I have a checkbox on MenuItem like this
<MenuItem Header="FullScreen"
Click="FullScreen"
IsChecked="{Binding IsFullScreen}">
</MenuItem>
I just want to set the checkbox with true or false on my MenuItem BUT when my bool changes, I see the getter being called but checkbox state doesn't change.
private bool? isFullScreen;
public bool? IsFullScreen
{
get { return isFullScreen ?? false; }
set
{
if (isFullScreen == value)
return;
isFullScreen = value;
OnPropertyChanged();
}
}
I've other part of XAML binding to IsFullScreen (not a checkbox) and works fine.
<DataTrigger Binding="{Binding IsFullScreen}" Value="True">
<Setter Property="Visibility" Value="Collapsed" TargetName="MainDock"/>
<Setter Property="BorderThickness" Value="0 0 0 0"/>
</DataTrigger>
(code above is working)
I saw a lot of solutions here but none helped me
What is the right way? Why my IsChecked don't work as should?
EDIT
My OnPropertyChanged
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
EDIT 2
Tried with: Mode=TwoWay, Converter, bool
Im setting true or false on code behind in click event.
Code with bool
public bool IsFullScreen
{
get { return isFullScreen; }
set
{
if (isFullScreen == value)
return;
isFullScreen = value;
OnPropertyChanged();
}
}
EDIT 3
Part of fullscreen click
private void FullScreen(object sender, RoutedEventArgs e)
{
if (this.WindowStyle == WindowStyle.None)
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.ResizeMode = ResizeMode.CanResize;
this.WindowState = WindowState.Normal;
IsFullScreen = false;
LogReport.Instance.Log("Modo FullScreen foi desativado");
}
else
{
this.WindowState = WindowState.Normal; // if don't set dont works well
this.WindowStyle = WindowStyle.None;
this.ResizeMode = ResizeMode.NoResize;
this.WindowState = WindowState.Maximized;
IsFullScreen = true;
LogReport.Instance.Log("Modo FullScreen foi ativado");
}
}
Already tried with e.Handled = true
IsFullScreen
from event handler is the same from ViewModel. Do you use Window as ViewModel? What is DataContext for your window? – Rekshinothis
manually – Kevin Kouketsu