通过向左和向右滚动从项目列表中选择项目

时间:2016-05-19 13:08:07

标签: c# wpf scrollview itemscontrol

我想在向右或向左滚动时选择下一个项目

   <StackPanel >
            <StackPanel Width="500">
                <ItemsControl ItemsSource="{Binding Devices}" Focusable="False" >

                    <ItemsControl.Template>
                        <ControlTemplate TargetType="{x:Type ItemsControl}" >
                            <ScrollViewer  HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" 
                                           CanContentScroll="True" Template="{DynamicResource ScrollViewerControlTemplate1}" 
                                           helpers:ScrollBarVisibilityHelper.IsEnabled="True" >
                                <ItemsPresenter />
                            </ScrollViewer>
                        </ControlTemplate>
                    </ItemsControl.Template>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Views:DeviceMiniView DataContext="{Binding}" Margin="10,5" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.Style>
                        <Style TargetType="{x:Type ItemsControl}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}"
                                    Value="0">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <StackPanel>
                                                    <TextBlock Text="No devices" FontSize="24" FontWeight="Bold"
                                                        Margin="0,0,0,20" Foreground="#FFF8F5F5" />
                                                    <TextBlock Text="Click Menu-&gt;Reconnect" FontSize="24"
                                                        FontWeight="Bold" Margin="0,0,5,0" Foreground="White" />
                                                </StackPanel>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}"
                                    Value="1">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate />
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ItemsControl.Style>
                </ItemsControl>
            </StackPanel>

enter image description here

我正在尝试滚动我在scrollViwer中存在的项目,从项目列表中滚动一次,但不幸的是我没有成功, 我是WPF新手,

我有Xaml:

<ItemsControl.Template>
    <ControlTemplate TargetType="{x:Type ItemsControl}" >
        <ScrollViewer  
            HorizontalScrollBarVisibility="Visible" 
            VerticalScrollBarVisibility="Disabled" 
            CanContentScroll="True" 
            Template="{DynamicResource ScrollViewerControlTemplate1}" 
            helpers:ScrollBarVisibilityHelper.IsEnabled="True"
            >
            <ItemsPresenter />
        </ScrollViewer>
    </ControlTemplate>
</ItemsControl.Template>

任何人都可以帮助我,我试图改变风格,模板,并尝试使用视图模型中的collectionview和可观察集合。 我会感激不尽的。

0 个答案:

没有答案