ScrollViewer的滚动问题(ScrollViewer里添加stackPanel,再加俩个listbox无法滚动的问题)

来源:互联网 发布:javascript案例教程 编辑:程序博客网 时间:2024/06/04 18:21
转自


http://blog.csdn.net/haylhf/article/details/8351203

如果scrollviewr里有一个listbox可以滚动,如果加个面板,放俩个listbox就无法滚动。两天都没进展,突然眼前一亮搜出来,代码搬运工的悲哀......,感谢前辈了。

每次都换个关键字搜索下试试。搜来搜去就喷到了。。。。。。

我的页面为

<Window x:Class="WpfApplication17.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" WindowState="Maximized" Loaded="Window_Loaded">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <ScrollViewer Grid.Column="0" Width="auto">
        <StackPanel  Orientation="Horizontal" Width="auto" Background="Aquamarine">

                <ListBox Name="LB1"  HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
                    <ListBoxItem>
                        <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                    </ListBoxItem>
                    <ListBoxItem>
                        <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                    </ListBoxItem>
                    <ListBoxItem>
                        <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                    </ListBoxItem>
                    <ListBoxItem>
                        <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                    </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
            </ListBox>
            <ListBox Name="LB2"  HorizontalAlignment="Right" >
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/1.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/2.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/3.jpg"></Image>
                </ListBoxItem>
                <ListBoxItem>
                    <Image   Height="90" Width="160" Source="/WpfApplication17;component/image/4.jpg"></Image>
                </ListBoxItem>
            </ListBox>
            <!----></StackPanel>
    </ScrollViewer>
        <Grid Grid.Column="1" Background="Aqua"></Grid>
</Grid>
</Window>


cs为

        public void bindLBX()
        {
       
       
            LB1.PreviewMouseWheel += (sender, e) =>
            {

                var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);

                eventArg.RoutedEvent = UIElement.MouseWheelEvent;

                eventArg.Source = sender;

                this.LB1.RaiseEvent(eventArg);
               
            };

            LB2.PreviewMouseWheel += (sender, e) =>
            {

                var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);

                eventArg.RoutedEvent = UIElement.MouseWheelEvent;

                eventArg.Source = sender;

                this.LB2.RaiseEvent(eventArg);

            };
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            bindLBX();
        }



1 0
原创粉丝点击