积极答复者
MultiTrigger的逻辑操作是不是过于简单了,条件间只能为且关系,要是Trigger之间的Setter有不少相同的岂不会产生很多冗余代码

问题
-
比如默认样式为style1,满足条件A样式设置为style2,满足条件B样式也为style2。
贴一段我的GridSplitter样式代码吧,希望有高人指点一二,本人感激不尽。默认样式为竖直的切分条,设置VerticalAlignment="Top"或VerticalAlignment="Bottom"时为水平的切分条。
<Style TargetType="{x:Type GridSplitter}"> <Style.Setters> <Setter Property="Background" Value="{StaticResource VerticalSplitterBrushNomal}"/> <Setter Property="Width" Value="6"/> </Style.Setters> <Style.Triggers> <Trigger Property="VerticalAlignment" Value="Bottom"> <Setter Property="Background" Value="{StaticResource HorizontalSplitterBrushNomal}"/> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="Width" Value="auto"/> <Setter Property="Height" Value="6"/> </Trigger> <Trigger Property="VerticalAlignment" Value="Top"> <Setter Property="Background" Value="{StaticResource HorizontalSplitterBrushNomal}"/> <Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="Width" Value="auto"/> <Setter Property="Height" Value="6"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="{StaticResource VerticalSplitterBrushHover}"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="VerticalAlignment" Value="Bottom"/> <Condition Property="IsMouseOver" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="{StaticResource HorizontalSplitterBrushHover}"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="VerticalAlignment" Value="Top"/> <Condition Property="IsMouseOver" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="{StaticResource HorizontalSplitterBrushHover}"/> </MultiTrigger> </Style.Triggers> </Style>
答案
-
你好,
WPF的XAML本意不是提供给你写逻辑的地方,如果你想完成更复杂些的逻辑, 你可以在后台代码完成。
如果你想完成“或”的条件,而不是“且”, 你可以用普通的trigger而不是multitrigger。
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 峰顶飞龙 2011年10月20日 2:09
全部回复
-
你好,
WPF的XAML本意不是提供给你写逻辑的地方,如果你想完成更复杂些的逻辑, 你可以在后台代码完成。
如果你想完成“或”的条件,而不是“且”, 你可以用普通的trigger而不是multitrigger。
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 峰顶飞龙 2011年10月20日 2:09
-
没什么可以简化的
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.