【发布时间】:2016-05-19 06:25:07
【问题描述】:
下面是我的 XAML 代码,用于设计带有选择突出显示的水平菜单。我实现了突出显示所选项目,但每个项目都显示项目采用完整设计
<ListBox x:Name="ListboxTest" ItemsSource="{Binding ScheduleScreenItems}" Background="Gray" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionChanged="ListboxTest_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionMode="Single">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<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="Transparent"/>
</Storyboard>
</VisualState>
<VisualState x:Name="SelectedUnfocused">
<Storyboard>
<ColorAnimation Duration="0" Storyboard.TargetName="myback" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" To="Red"/>
</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>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel >
<TextBlock Text="{Binding DayName}" FontFamily="Times New Roman" FontWeight="SemiBold" Height="25" TextAlignment="Center" Padding="0 0 0 0" Margin="0 0 0 0" Width="100" FontSize="18" Foreground="White" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Date}" FontWeight="SemiBold" FontSize="18" Margin="0 10 0 0" Foreground="White" HorizontalAlignment="Center" />
<Line X1="0" Y1="-70" X2="0" Y2="50"
Stroke="White"
StrokeThickness="2" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
请指导我解决问题。
【问题讨论】:
-
将此
ScrollViewer.HorizontalScrollMode="Enabled"添加到ListView -
感谢您的回复@LovetoCode。我包括但它不起作用。
-
对不起,你也应该添加这些 `
' -
你能具体指导我哪里需要更新代码
-
添加了答案。请参考
标签: xaml listbox windows-phone-8.1