我想简单地在我的 LongListSelector 中显示当前所选项目的边框。我为我的 LongListSelector 设置了一个 ItemTemplate,但我不确定如何修改边框,以便只有当前选定的项目包含边框。
主页.xaml
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="ItemTemplate">
<!-- BorderBrush of all items are currently set to PhoneAccentBrush, need only currently selected item! -->
<Border x:Name="brd" CornerRadius="10" BorderBrush="{StaticResource PhoneAccentBrush}" Width="Auto" BorderThickness="3">
<Viewbox Width="108" Height="108">
<Image x:Name="recentImage" Source="{Binding Source}" Margin="6,6" Width="108"/>
</Viewbox>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="imgListContextMenu" Background="{StaticResource PhoneChromeBrush}">
<toolkit:MenuItem Foreground="{StaticResource PhoneForegroundBrush}" Header="delete" Click="deleteContextMenuItem_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Border>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
...
<phone:LongListSelector x:Name="Recent" Margin="0"
SelectionChanged="recent_SelectionChanged"
toolkit:TiltEffect.IsTiltEnabled="True"
LayoutMode="Grid" GridCellSize="108,108"
ItemTemplate="{StaticResource ItemTemplate}"
/>
目前所有的项目都LongListSelector
显示在边框内。我宁愿在后面的代码中修改它,但到目前为止我所拥有的不起作用
MainPage.xaml.cs
private void recent_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var item = sender as LongListSelector
item.BorderBrush = App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;
}
有任何想法吗?