【发布时间】:2014-10-06 17:10:56
【问题描述】:
我是使用 MVVM 构建 Windows Phone 应用程序的新手。
我的任务是:
当我选择行时,它应该是蓝色背景。在每一行我都有图像,当我点击图像时,行应该是黄色的。
我有没有代码:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="White"/>
</Storyboard>
</VisualState>
<VisualState x:Name="SelectedUnfocused">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="LightBlue"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="myback" Background="Transparent">
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
当我选择行时,此代码可帮助我更改背景颜色。我也有绑定到 SelectedIndex 的属性。
当我点击该行的图像时如何为该行制作黄色背景?
谢谢
【问题讨论】:
-
添加 ListView 的其余代码。具体来说,就是 ItemTemplate。
标签: c# xaml listview windows-phone-8 mvvm