AdaptiveTrigger and DataTemplate(自适应触发器和数据模板)
问题描述
AdaptiveTrigger 可以在 DataTemplate 中工作吗?
Will AdaptiveTrigger work in a DataTemplate?
这是我用来自定义 ShellNavigation 的代码,除了视觉状态外,它工作正常.他们不会触发任何事情.
That's my code i'm using to customize my ShellNavigation, it is working fine except the visual states. They will not trigger anything.
<shell:ShellHeadView x:Key="ShellHeadView_01">
<shell:ShellHeadView.ContentTemplate>
<DataTemplate>
<Grid Margin="20,0">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="GreenBackgroundVisualState">
<VisualState.Setters>
<Setter Target="headViewLeft.Background" Value="Green" />
</VisualState.Setters>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1000"/>
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="OrangeBackgroundVisualState">
<VisualState.Setters>
<Setter Target="headViewLeft.Background" Value="Orange" />
</VisualState.Setters>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="2000"/>
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="RedBackgroundVisualState">
<VisualState.Setters>
<Setter Target="headViewLeft.Background" Value="Red" />
</VisualState.Setters>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="3000"/>
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="headViewLeft" Width="100" Height="90">
</Grid>
推荐答案
尝试像这样将您的 DataTemplate
包装在 UserControl
中 -
Try wrapping your DataTemplate
inside a UserControl
like this -
<DataTemplate>
<UserControl>
<Grid>
<VisualStateManager.VisualStateGroups>
...
</Grid>
</UserControl>
</DataTemplate>
<小时>
看起来任何具有 Content
属性的 Control
都可以工作.这就是 UserControl
起作用的原因,ContentControl
也是如此.
Looks like any Control
that has got a Content
property will work. That's why UserControl
works, so does a ContentControl
.
因此,如果您将 UserControl
替换为 ContentControl
并给它一个空的 Style
.它也应该可以工作.
So if you replace the UserControl
with a ContentControl
and give it an empty Style
. It should work too.
<Style x:Key="EmptyContentControlStyle" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl" />
</Setter.Value>
</Setter>
</Style>
<DataTemplate>
<ContentControl Style="{StaticResource EmptyContentControlStyle}">
<Grid>
<VisualStateManager.VisualStateGroups>
...
</Grid>
</ContentControl>
</DataTemplate>
这篇关于自适应触发器和数据模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自适应触发器和数据模板


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01