我想在我的LongListSelector中简单地显示当前选定项目的边框。我为我的LongListSelector设置了一个ItemTemplate,但我不确定如何修改边框,以便只有当前选定的项目包含边框。如何突出显示LongListSelector中的选定项目
MainPage.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;
}
任何想法?
出于某种原因,我无法将其适用于我的解决方案。 – Matthew
@Mthethew它为我工作得很好。我在选择时采用了同样的突出显示项目,因为我在后面的代码中设置所选项目时遇到了麻烦。这对你来说是一个问题吗? –
我其实去了一个略有不同的解决方案http://stackoverflow.com/questions/18436328/how-to-create-border-around-longlistselector-selecteditem/18438027?noredirect=1#18438027,我认为你会感兴趣在检查。我会将你的标记标记为正确的,因为我知道它也适用。我很感激! – Matthew