Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 接受参数的WPF数据触发器?_C#_Wpf_Xaml_Datatrigger_Multibinding - Fatal编程技术网

C# 接受参数的WPF数据触发器?

C# 接受参数的WPF数据触发器?,c#,wpf,xaml,datatrigger,multibinding,C#,Wpf,Xaml,Datatrigger,Multibinding,我在XAML中定义了以下样式,仅当DataContext中的某些内容发生更改时(IsDirty=true)才启用按钮: 只要UserControl中只有一个DataContext,这就可以工作。现在的情况是,我有3个不同的数据视图,所以我有3个不同的IsDirty值(即CustomerTableIsDirty、OrderTableIsDirty、OrderDetailTableIsDirty)。在这种情况下,我可以在UserControl中创建三个新的*DisableWhenDirtyBut

我在XAML中定义了以下样式,仅当DataContext中的某些内容发生更改时(IsDirty=true)才启用按钮:


只要UserControl中只有一个DataContext,这就可以工作。现在的情况是,我有3个不同的数据视图,所以我有3个不同的IsDirty值(即CustomerTableIsDirty、OrderTableIsDirty、OrderDetailTableIsDirty)。在这种情况下,我可以在UserControl中创建三个新的*DisableWhenDirtyButtonStyle,如下所示:

        <Style x:Key="CustomerTableEnableWhenDirtyButtonStyle" 
               TargetType="{x:Type Button}" 
               BasedOn="{StaticResource ButtonStyle}">
            <Setter Property="Button.IsEnabled" Value="False" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=CustomerTableIsDirty}" Value="true">
                    <Setter Property="Button.IsEnabled" Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style>

是否有方法创建DataTrigger,以便绑定值可以作为参数传递到样式中

或者,当通过“BasedOn”继承样式时,是否有一种方法可以向MultiDataTrigger添加条件,该样式已经定义了MultiDataTrigger。例如:

<Style x:Key="CustomerTableEnableWhenDirtyButtonStyle" 
                   TargetType="{x:Type Button}" 
                   BasedOn="{StaticResource EnableWhenDirtyButtonStyle}">

     <!-- Add the following to existing MultiDataTrigger in EnableWhenDirtyButtonStyle -->
     <Condition Binding="{Binding Path=CustomerTableIsDirty}" Value="true" />

</Style>


我不能使用多重绑定,因为这种样式是由多个其他项目(作为DLL)使用的基础项目的一部分。此DLL的用户将无法更新样式以包含必要的绑定路径。

只使用一个名称IsDirty,而不是使用3个不同的名称。

创建附加行为如何?由于所有这些都在一个UserControl上,CustomerTableIsDirty、OrderTableIsDirty、OrderDetailTableIsDirty的值都在一个ViewModel中。简单地将它们命名为“IsDirty”不是一个选项。我没有在我的帖子中提到它,但是每个表都有自己的保存按钮,我正在尝试只启用特定的按钮。
<Style x:Key="CustomerTableEnableWhenDirtyButtonStyle" 
                   TargetType="{x:Type Button}" 
                   BasedOn="{StaticResource EnableWhenDirtyButtonStyle}">

     <!-- Add the following to existing MultiDataTrigger in EnableWhenDirtyButtonStyle -->
     <Condition Binding="{Binding Path=CustomerTableIsDirty}" Value="true" />

</Style>