WPF Scrollviewer无法水平滚动

时间:2015-03-27 17:43:10

标签: wpf wpf-controls scrollviewer

我无法找到一种在水平滚动查看器中制作这些图像的方法。

他们喜欢这个

IMAGE1
IMAGE2
IMAGE3

我想要

IMAGE1 IMAGE2 IMAGE3

所以我可以水平滚动它们。我已经尝试过谷歌和stackoverflow,但我找不到可行的解决方案:(

代码

<Window x:Class="TESSTTTTTT.MirrorWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MirrorWindow" HorizontalAlignment="Center" VerticalAlignment="Center" WindowStyle="None">
    <Grid Name="grid2" HorizontalAlignment="Center" VerticalAlignment="Stretch">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" Name="ColumnKinect">
            <Image Name="camera2" Height="1800" Width="3200" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <!--
        <Canvas Name="canvas2" Height="1800" Width="3200" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Hidden"  />-->
            <Image Name="imgBodyFrame" Source="{Binding MainWindow.ImageSource}" Height="1800" Width="3200"/>
            <!--Stretch="UniformToFill"-->

            <Image Name="img3DBodyRotation" Source="{Binding MainWindow.ImageSource}" Height="1800" Width="3200" Visibility="Hidden"/>
        </Grid>
        <Grid Grid.Column="1" Height="1800" Width="3200" HorizontalAlignment="Stretch" VerticalAlignment="Top" Name="ColumnCatalogo">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <ScrollViewer Grid.Row="0" Name="scrollViewerCatalogo" Background="AliceBlue"
                                  HorizontalScrollBarVisibility="Disabled"
                                  VerticalScrollBarVisibility="Visible">
                <ItemsControl Grid.Row="0" Name="itemsControl" HorizontalAlignment="Center" VerticalAlignment="Stretch">
                    <ItemsControl Name="itcCatalogo" HorizontalContentAlignment="Left">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <ListBox Width="Auto" Height="Auto" HorizontalContentAlignment="Left">
                                    <WrapPanel Orientation="Horizontal" Width="Auto" Height="Auto">
                                        <StackPanel Name="stpProduct" Orientation="Vertical">
                                            <TextBlock Width="Auto" Height="Auto" Text="{Binding Nome}" Foreground="#006b66" FontFamily="Verdana" FontSize="14" FontWeight="ExtraBold"/>
                                            <Image Width="400" Height="300" Source="{Binding PathImmagine}"/>
                                            <TextBlock Width="Auto" Height="Auto" Foreground="#006b66" FontFamily="Verdana" FontSize="20" FontWeight="Bold">
                                            <Run Text="Prezzo a partire da: "/>
                                             <LineBreak/>
                                             <Run Text="{Binding Prezzo}"/>
                                            <Run Text="€"/>
                                            </TextBlock>
                                            <TextBlock Width="Auto" Height="Auto" Text="{Binding Rigidita}" Foreground="Gray" FontFamily="Verdana" FontSize="20" FontWeight="ExtraBold"/>
                                        </StackPanel>
                                    </WrapPanel>
                                </ListBox>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ItemsControl>
            </ScrollViewer>
        </Grid>
    </Grid>
</Window>

3 个答案:

答案 0 :(得分:0)

我不确定你是在谈论图像,Image1 Image2 Image3。你会在给定的代码片段中提到它们。由于我不确定这个问题,我添加了两个场景。

场景1:我可以在第0列看到3个Image控件。如果需要水平显示它们,可以使用StackPanel而不是Grid,并可以将Orientation属性用作Horizo​​ntal。或者您需要向第0列网格添加3列,您可以分别添加这些图像。

场景2:在第一个网格中,你有一个scrollviewer,如果你需要在它们内部水平可见的图像控件,你可以使用StackPanel的Orientation属性(在wrappanel内的stackpanel)到Horizo​​ntal而不是垂直。

希望这会对你有所帮助。

答案 1 :(得分:0)

<ScrollViewer HorizontalScrollBarVisibility="Visible">
        <StackPanel Orientation="Horizontal">
            <Button Content="Button1" Foreground="Red" />
            <Button Content="Button2" Foreground="Red" />
            <Button Content="Button3" Foreground="Red" />
            <Button Content="Button4" Foreground="Red" />
            <Button Content="Button5" Foreground="Red" />
            <Button Content="Button6" Foreground="Red" />

        </StackPanel>
    </ScrollViewer>

答案 2 :(得分:0)

尝试这种方式,将自定义面板模板添加到水平列表框中。

        <Window x:Class="TESSTTTTTT.MirrorWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                Title="MirrorWindow" HorizontalAlignment="Center" VerticalAlignment="Center" WindowStyle="None">
            <Grid Name="grid2" HorizontalAlignment="Center" VerticalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" Name="ColumnKinect">
                    <Image Name="camera2" Height="1800" Width="3200" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    <!--
                <Canvas Name="canvas2" Height="1800" Width="3200" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Hidden"  />-->
                    <Image Name="imgBodyFrame" Source="{Binding MainWindow.ImageSource}" Height="1800" Width="3200"/>
                    <!--Stretch="UniformToFill"-->

                    <Image Name="img3DBodyRotation" Source="{Binding MainWindow.ImageSource}" Height="1800" Width="3200" Visibility="Hidden"/>
                </Grid>
                <Grid Grid.Column="1" Height="1800" Width="3200" HorizontalAlignment="Stretch" VerticalAlignment="Top" Name="ColumnCatalogo">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <ScrollViewer Grid.Row="0" Name="scrollViewerCatalogo" Background="AliceBlue"
                                          HorizontalScrollBarVisibility="Visible"
                                          VerticalScrollBarVisibility="Visible">
                        <ItemsControl Grid.Row="0" Name="itemsControl" HorizontalAlignment="Center" VerticalAlignment="Stretch">
                            <ItemsControl Name="itcCatalogo" HorizontalContentAlignment="Left">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>

                                    <DataTemplate>
                                        <ListBox Width="Auto" Height="Auto" HorizontalContentAlignment="Left">
                                            <WrapPanel Orientation="Horizontal" Width="Auto" Height="Auto">
                                                <StackPanel Name="stpProduct" Orientation="Vertical">
                                                    <TextBlock Width="Auto" Height="Auto" Text="{Binding Nome}" Foreground="#006b66" FontFamily="Verdana" FontSize="14" FontWeight="ExtraBold"/>
                                                    <Image Width="400" Height="300" Source="{Binding PathImmagine}"/>
                                                    <TextBlock Width="Auto" Height="Auto" Foreground="#006b66" FontFamily="Verdana" FontSize="20" FontWeight="Bold">
                                                    <Run Text="Prezzo a partire da: "/>
                                                     <LineBreak/>
                                                     <Run Text="{Binding Prezzo}"/>
                                                    <Run Text="€"/>
                                                    </TextBlock>
                                                    <TextBlock Width="Auto" Height="Auto" Text="{Binding Rigidita}" Foreground="Gray" FontFamily="Verdana" FontSize="20" FontWeight="ExtraBold"/>
                                                </StackPanel>
                                            </WrapPanel>
                                        </ListBox>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ItemsControl>
                    </ScrollViewer>
                </Grid>
            </Grid>
        </Window>