Reputation: 36166
I have a checkable DropDownButton and a Grid.
I want to bind Button's IsChecked parameter with grid's Visibility value.
If (Visibility == Visible) IsCheked = true
I've tried to do like that:
IsChecked="{Binding ElementName=UsersDockWindow, Path=IsVisible}"
but it didn't work, cause IsVisible is readOnly property.
Upvotes: 0
Views: 2379
Reputation: 74802
Create a VisibilityToBooleanConverter and use that in your binding:
public class VisibilityToBooleanConverter : IValueConverter
{
public object Convert(object value, ...)
{
return (Visibility)value == Visibility.Visible;
}
}
In your XAML:
<Window.Resources>
<!-- assuming the local: xmlns is mapped to the appropriate namespace -->
<local:VisibilityToBooleanConverter x:Key="vbc" />
</Window.Resources>
IsChecked="{Binding Visibility,
ElementName=UsersDockWindow,
Converter={StaticResource vbc}}"
Upvotes: 1
Reputation: 75982
Use the BooleanToVisibilityConverter
. Here's an example of how to do the binding using that converter.
Upvotes: 4