我有一个列表框,其中有为ItemContainer和ItemTemplate样式定义的模板。
我的ItemTemplate是一个非常简单的数据模板:
<DataTemplate x:Key="DataTemplate1">
<Grid x:Name="grid">
<TextBlock TextWrapping="Wrap" Text="{Binding}" Foreground="White" FontSize="24" />
</Grid>
</DataTemplate>
而ItemContainer也非常简单:
<Grid x:Name="Grid" HorizontalAlignment="Stretch" Height="Auto" SnapsToDevicePixels="true" Width="373" Background="{x:Null}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="37"/>
</Grid.ColumnDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected"/>
<VisualState x:Name="SelectedUnfocused"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="contentPresenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Stretch" Margin="2,0,0,0" d:LayoutOverrides="Width">
</ContentPresenter>
<Image x:Name="image" HorizontalAlignment="Center" Margin="0,0,0,1" Source="/MyApp;component/Images/icon_arrowcircle.png" Stretch="Uniform" Width="37" Grid.Column="1" VerticalAlignment="Center" Opacity="0"/>
</Grid>
一切正常。
但我想做的是,当一个项目被选中时(即选中的视觉状态),我希望数据模板中的文本块将其前景颜色更改为黑色而不是白色,并使字体大小更大。但我似乎找不到一个干净的方法来完成这项工作,因为模板绑定似乎无法从数据模板中获得。
有什么想法吗?