Reputation: 346
I have a border surrounding an element whose visibility is bound to that element like so:
<Border Grid.Column="1" Grid.Row="1" BorderBrush="White" BorderThickness="1" Height="27" Width="112"
Visibility="{Binding IsVisible, ElementName=MinPart, Converter={StaticResource BoolToVisConv}}">
<wpfTool:DecimalUpDown x:Name="MinPart" Value="1.0" FontSize="13" />
</Border>
The code behind for the BoolToVisConv converter is:
public class BooleanToVisibilityConverter : IValueConverter
{
private object GetVisibility(object value)
{
if (!(value is bool))
return Visibility.Hidden;
bool objValue = (bool)value;
if (objValue)
{
return Visibility.Visible;
}
else
{
return Visibility.Hidden;
}
}
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return GetVisibility(value);
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
I am trying to make it so that if the MinPart is set to visible, the border is set to visible. Right now, if even once the border becomes hidden, the MinPart control is hidden permanently (setting it's visibility to visible doesn't un-do that). I'm pretty sure that it's because of the loop that it's trapped in. Therefore, I think that I should set the border property of the border rather than setting the visibility, but I don't know how to bind the border to the visibility of control MinPart without creating a new converter. In other words, how do I over load the BooleanToVisibilityConverter so that it can detect the object who's visibility is being sent to it?
Upvotes: 4
Views: 6539
Reputation: 5951
When your controls are nested, this implies that if you make the parent not visible, then the child control will be not visible.
Try pulling your child control out and put it just below the border definition:
<Border Grid.Column="1" Grid.Row="1" BorderBrush="White" BorderThickness="1" Height="27" Width="112"
Visibility="{Binding IsVisible, ElementName=MinPart, Converter={StaticResource BoolToVisConv}}"/>
<wpfTool:DecimalUpDown x:Name="MinPart" Value="1.0" FontSize="13" />
Upvotes: 3