如何通过 WPF DataTrigger 在多值转换器中传递多个参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35266611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Pass multiple parameter in Multivalue Converter Over WPF DataTrigger
提问by B.Balamanigandan
I'm having four intProperty ProOne, ProTwo, ProThreeand ProFour
我有四个intProperty ProOne, ProTwo,ProThree和ProFour
I have to Implement the Boolean Logic ((ProOne == ProTwo) || (ProThree == ProFour))in the Multivalue Converter namely VisibilityCheckConverter. Based on the Logic the Multivalue Converter VisibilityCheckConverterreturns Trueor False.
我必须((ProOne == ProTwo) || (ProThree == ProFour))在多值转换器中实现布尔逻辑,即VisibilityCheckConverter. 根据多值转换器VisibilityCheckConverter返回的逻辑True或False。
Now I need to pass the four properties to the Converter over DataTrigger, Based on the Value, I have to change the Buttons Visibility to Visible
现在我需要通过 DataTrigger 将四个属性传递给 Converter,根据值,我必须将 Buttons Visibility 更改为 Visible
How does one write the a DataTrigger using Multivalue Converter with multiple parameters?
如何使用具有多个参数的多值转换器编写数据触发器?
Sample Piece of XAML Code:
XAML 代码示例:
<ControlTemplate.Triggers>
<DataTrigger Property="{Binding , Converter={StaticResource VisibilityCheckConverter,ConverterParameter=ProOne ProTwo ProThree ProFour}}" Value="true">
<Setter TargetName="Button" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
回答by Nikhil Agrawal
You can do something like this
你可以做这样的事情
<Style.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource VisibilityCheckConverter}">
<Binding Path="ProOne" />
<Binding Path="ProTwo" />
<Binding Path="ProThree" />
<Binding Path="ProFour" />
</MultiBinding>
</DataTrigger.Binding>
<Setter TargetName="Button" Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>

