Okay, I'm getting highly frustrated right now, and keep in mind that I am brand new to WPF and binding so..
I have a
Datagrid (that is within a tabcontrol). Within the Datagrid is an expander. I have a checkbox at the top of the Window called chkExpandAll. I want to bind the IsExpanded of the expander to the IsChecked of the checkbox. In other words I wish to expand all of the expanders in the datagrid when I select the checkbox.
In my Windows Resources section I have:
<local:BooleanToVisibilityConverter x:Key="boolConvertNormal" />
The checkbox is listed as:
<CheckBox Content="Expand All" Name="chkExpandAll" VerticalAlignment="Center" Margin="5,0,5,0" />
And then on my expander I have this:
<Expander Header="{Binding}" IsExpanded="{Binding IsChecked, ElementName=chkExpandAll, Converter={StaticResource ResourceKey=boolConvertNormal}, Mode=TwoWay}" >
When I run the app and then click the checkbox nothing happens.
Oh, and here is the code for the resource:
public sealed class BooleanToVisibilityConverter : IValueConverter
{
public bool IsReversed { get; set; }
public bool UseHidden { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var val = System.Convert.ToBoolean(value, CultureInfo.InvariantCulture);
if (this.IsReversed)
{
val = !val;
}
if (val)
{
return Visibility.Visible;
}
return this.UseHidden ? Visibility.Hidden : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}