开发Windows 10 Universal App,我无法获得可视状态触发器来更改ListView中ItemTemplate中使用的TextBlock的字体大小。我试图将触发器用于任何其他元素,但是当我调整窗口大小时它不会改变字体大小。以下是我的xaml页面的主要代码:
项目模板:
<Page.Resources>
<ResourceDictionary>
<DataTemplate x:Key="PresentationItemTemplate">
<TextBlock x:Name="PresentationListViewItemTextBlock"
x:Uid="PresentationListViewItemTextBlock"
Text="{Binding Title}"
HorizontalAlignment="Center"/>
</DataTemplate>
</ResourceDictionary>
</Page.Resources>
视觉状态触发器:
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowHeight="{StaticResource Height1}"
MinWindowWidth="{StaticResource Width1}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="PresentationListViewItemTextBlock.FontSize" Value="40"/>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource Width2}"
MinWindowHeight="{StaticResource Height2}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="PresentationListViewItemTextBlock.FontSize" Value="20"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
页面中ListView的定义:
<ListView x:Name="AvailablePresentationsListView"
x:Uid="AvailablePresentationsListView"
DataContext="{Binding}"
ItemsSource="{Binding PresentationCollection}"
ItemTemplate="{StaticResource PresentationItemTemplate}"/>
我的猜测是在模板项的属性上设置状态触发器时出现问题。当我调整屏幕大小时,如何设置为ListView TextBlock项目设置不同的字体大小呢?感谢。