I implemented a textbox and it have to become visible when a checkbox is’nt checked and vica versa.
Here is my view:
<TextBox Visibility="{Binding VisiMaxTime}" Height="23" HorizontalAlignment="Left" Margin="165,36,0,0" Text="{Binding Path=MaxTime,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" VerticalAlignment="Top" Width="75" />
<CheckBox IsChecked="{Binding MaxTimeIsChecked}" Content="Geen" FontWeight="Bold" Height="16" HorizontalAlignment="Left" Margin="104,39,0,0" Name="checkBox1" VerticalAlignment="Top" />
And this is my viewmodel:
public bool MaxTimeIsChecked
{
get { return maxTimeIsChecked; }
set
{
maxTimeIsChecked = value;
if (maxTimeIsChecked == true)
{
VisiMaxTime = Visibility.Hidden;
this.Examination.MaxTime = 0;
}
else
VisiMaxTime = Visibility.Visible;
OnPropertyChanged("MaxTimeIsChecked");
}
}
private Visibility visiMaxTime;
public Visibility VisiMaxTime
{
get { return visiMaxTime; }
set
{
visiMaxTime = value;
OnPropertyChanged("VisiMaxTime");
}
}
So i think this is good, this works in usercontrols but now i am working in a window. If i set a breakpoint in the setters of Visibility, it works fine, but the textbox just does’nt become visible? Does somebody know what i am doing wrong?
Thanks
if the visiblity of the textbox depends on Checkbox, why not bind to that directly?
you will need to use BooleanToVisibilityConverter to convert Bool to Visiblity