Reputation: 9080
I have a textbox in my WPF application and it is currently displaying if a dependency property is set. I'm wondering if there is a way to display this textbox using an OR statement?
<TextBox Grid.Row="1" Height="23" Width="132" Margin="451,30,0,0"
Text="{Binding Path=PositionName}"
Style="{StaticResource TextBoxStyleValue}"
Visibility="{Binding IsDepProp1, Converter={StaticResource BooleanToVisibilityConverter},
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
Something like:
Binding IsDepProp1 || IsDepProp2
Upvotes: 0
Views: 60
Reputation: 81233
IMultiValueConverter is a way to go but however you can achieve that using two DataTriggers as well like this:
<TextBox Grid.Row="1" Height="23" Width="132" Margin="451,30,0,0"
Text="{Binding Path=PositionName}">
<TextBox.Style>
<Style TargetType="TextBox" BasedOn="{StaticResource TextBoxStyleValue}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsDepProp1,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsDepProp2,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
Default value will be Collapsed
and based on two triggers you can check if any of the property returns true, set visibility to Visible
.
Upvotes: 1
Reputation: 10507
I belive you are looking for MultiBinding
.
Check out: http://tech.pro/tutorial/809/wpf-tutorial-using-multibindings for a good explanation.
Basically though, you will have to implement IMultiValueConverter
and use it for your value converter.
Upvotes: 2