【问题标题】:ListBoxItem in VerticallyListBoxItem 垂直
【发布时间】: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


【解决方案1】:

您应该将ItemsPanelTemplate's Orientation 更改为Horizontal

<ListBox  ItemsSource="{Binding ListTest}"  ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible"
                      ScrollViewer.VerticalScrollMode="Disabled"
                     x:Name="MyListView">
        <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 Orientation="Vertical"    >
                    <TextBlock Text="{Binding Name}"/>
                    <Line   X1="0" Y1="-70"  X2="0" Y2="50"
                                    Stroke="White"
                              StrokeThickness="2" />
                </StackPanel>

            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>

【讨论】:

  • 你能推荐一些其他的选择吗
  • 应该可以。我只是测试。它的工作。我将添加整个代码。只需检查
  • 谢谢@LovetoCode。它正在工作。但这份名单并没有完全到来。菜单列表有星期四、星期五、星期六、星期日、星期一、星期二和星期三。在菜单设计中,我可以到周四、周五、周六、周日、周一。我必须做些什么才能通过滚动获得完整列表
  • ScrollViewer.HorizontalScrollBarVisibility="Hidden"或可见ScrollViewer.HorizontalScrollBarVisibility="Visible"
  • 谢谢@LovetoCode。它按预期完美运行
猜你喜欢
  • 1970-01-01
  • 2013-10-15
  • 2012-10-30
  • 2021-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-29
  • 2015-04-24
相关资源
最近更新 更多