两个DataGrids上的MultiDataTrigger

时间:2013-05-24 12:42:12

标签: c# wpf silverlight xaml

我正在尝试让按钮处于禁用状态,直到两个DataGrids都至少有一个选定的项目。目前它仍处于启用状态。

<Button MaxWidth="200" Grid.Column="0" x:Name="Add" Content="{x:Static UiStrings:Labels.Add}" >
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=SelectedIndex, ElementName=EconomicFactors}" Value="-1"></Condition>
                        <Condition Binding="{Binding Path=SelectedIndex, ElementName=TargetTypes}" Value="-1"></Condition>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="IsEnabled" Value="False"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

此致

1 个答案:

答案 0 :(得分:3)

MultiDataTrigger中,所有条件都必须如此。我认为最简单的解决方案是将MultiDataTrigger替换为两个DataTrigger

<Style.Triggers>
    <DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=EconomicFactors}" Value="-1">
        <Setter Property="IsEnabled" Value="False"/>
    </DataTrigger>
    <DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=TargetTypes}" Value="-1">
        <Setter Property="IsEnabled" Value="False"/>
    </DataTrigger>
</Style.Triggers>