0

我有这个绑定,我们用它来选择性地显示/隐藏元素:

<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 或其他机制绑定这两个属性吗?

4

1 回答 1

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>
于 2015-01-21T20:42:19.537 回答