将此绑定转换为 MultiDataTrigger 绑定
Convert This Binding to MultiDataTrigger Binding
我有这个绑定,我们可以选择性地使用 display/hide 个元素:
<Binding XPath="InputFileIsNeeded">
<Binding.Converter>
<tl:IsEnabledToStringConverter
DisabledValue="Collapsed"
EnabledValue="Visible" />
</Binding.Converter>
</Binding>
我现在有一个元素,我需要根据上述绑定和对命令行参数的绑定有选择地 show/hide 'Setup':
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.StartArg}" Value="Setup">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
我需要将这两个绑定应用于以下内容,以便以下元素仅在处于 'Setup' 模式且 '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) Expected '}' (on "XPath=") 和 (2) 我显然不能在这里使用,因为没有特定元素(我认为这将在 Condition 元素内) .
谁能告诉我如何使用 MultiDataTrigger 或其他机制绑定这两个属性?
(以下信息由问题作者在编辑中提供。)
我找到了一个示例,可以根据我的具体情况进行修改。在 OP 中的 Style 添加了以下内容:
<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>
我有这个绑定,我们可以选择性地使用 display/hide 个元素:
<Binding XPath="InputFileIsNeeded">
<Binding.Converter>
<tl:IsEnabledToStringConverter
DisabledValue="Collapsed"
EnabledValue="Visible" />
</Binding.Converter>
</Binding>
我现在有一个元素,我需要根据上述绑定和对命令行参数的绑定有选择地 show/hide 'Setup':
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.StartArg}" Value="Setup">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
我需要将这两个绑定应用于以下内容,以便以下元素仅在处于 'Setup' 模式且 '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) Expected '}' (on "XPath=") 和 (2) 我显然不能在这里使用,因为没有特定元素(我认为这将在 Condition 元素内) .
谁能告诉我如何使用 MultiDataTrigger 或其他机制绑定这两个属性?
(以下信息由问题作者在编辑中提供。)
我找到了一个示例,可以根据我的具体情况进行修改。在 OP 中的 Style 添加了以下内容:
<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>