views:

110

answers:

2

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.

+4  A: 

Use the BooleanToVisibilityConverter. Here's an example of how to do the binding using that converter.

Franci Penov
IsCheckable="True" IsChecked="{Binding ElementName=UsersDockWindow, Path=Visibility, Converter={StaticResource VisibilityOfBool}}"Doesn't work... apparently I need somewhing opposite - VisibilityToBooleanConverter, but there is not such a thing
Ike
Why don't you put the binding on the `UsersDockWindow.Visibility` and make it one way to the source? If that doesn't work, you can quickly write your own converter, there are number of examples on the net how to do it.
Franci Penov
+1  A: 

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}}"
itowlson