我有这个用于选择性显示/隐藏元素的绑定:
<Binding XPath="InputFileIsNeeded">
<Binding.Converter>
<tl:IsEnabledToStringConverter
DisabledValue="Collapsed"
EnabledValue="Visible" />
</Binding.Converter>
</Binding>
我现在有一个元素,我需要根据上面的绑定和命令行参数'Setup'的绑定选择性地显示/隐藏:
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.StartArg}" Value="Setup">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
我需要将以下两个绑定应用于以下内容,因此仅在“设置”模式和“InputFileIsNeeded”为真时才显示以下元素:
<Style x:Key="ColumnCountSpinner" TargetType="{x:Type ScrollBar}">
<Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
<Setter Property="Width" Value="Auto"/>
<Setter Property="MinHeight" Value="25"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Content="Column Count:"
Grid.Column="0" />
<Border BorderThickness="1" BorderBrush="Gray" Grid.Column="1">
<Grid Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" FontSize="12" MinWidth="25" Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" />
<Grid Grid.Column="1" x:Name="GridRoot" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition MaxHeight="18"/>
<RowDefinition Height="0.00001*"/>
<RowDefinition MaxHeight="18"/>
</Grid.RowDefinitions>
<RepeatButton x:Name="DecreaseRepeat" Command="ScrollBar.LineDownCommand" Focusable="False">
<Grid>
<Path x:Name="DecreaseArrow" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" Data="M 0 4 L 8 4 L 4 0 Z"/>
</Grid>
</RepeatButton>
<RepeatButton Grid.Row="2" x:Name="IncreaseRepeat" Command="ScrollBar.LineUpCommand" Focusable="False">
<Grid>
<Path x:Name="IncreaseArrow" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" Data="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
</RepeatButton>
</Grid>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
我在如何将XPath绑定到MultiDataTrigger方面遇到了困难。我试图跟随但得到两个错误(1)预期'}'(在“XPath =”上)和(2)我显然不能在这里使用,因为没有特定元素(我认为这将在Condition元素内)。
有人可以告诉我如何使用MultiDataTrigger或其他一些机制绑定这两个属性吗?
答案 0 :(得分:0)
(以下信息由问题作者在编辑中提供。)
我找到了一个我能够根据具体情况修改的例子。以下内容添加到OP中的样式:
<Style.Triggers>
<MultiDataTrigger>
<!-- Condition for 'Setup' and InputFileIsNeeded = true -->
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.StartArg}" Value="Setup" />
<Condition Binding="{Binding XPath=InputFileIsNeeded}" Value="true" />
</MultiDataTrigger.Conditions>
</MultiDataTrigger>
<Style.Triggers>