WPF StackPanel项目应该重复

时间:2018-05-09 09:18:14

标签: c# wpf loops stackpanel items

我在C#WPF中运行时向Stack-panel添加按钮。我想要的是当我到达最后一次我希望它显示最后一个项目之后的第一个项目时,我滚动浏览堆栈面板项目的时间,以便它继续重复列表。

<ScrollViewer VerticalScrollBarVisibility="Hidden" CanContentScroll="True" HorizontalScrollBarVisibility="Hidden"
                              Name="SVMenu" Margin="-2,45,2,39" Grid.RowSpan="3">

                        <StackPanel x:Name="stackpanel_Menu1">

                        </StackPanel>
                </ScrollViewer>

这是创建按钮的代码。

 DataTable dt = db.VIEW_MENUS();
        foreach (DataRow dr in dt.Rows)
        {
            Button Btn = new Button();
            Label LB = new Label();
            Btn.Content = dr[1].ToString();
            Object obj = dr["MENUIMAGE"];
            if (obj != null)
            {
                try
                {
                    ImageBrush BtnBrush = new ImageBrush();
                    using (MemoryStream stream = new MemoryStream((byte[])obj))
                    {
                        BtnBrush.ImageSource = BitmapFrame.Create(stream,
                                          BitmapCreateOptions.None,
                                          BitmapCacheOption.OnLoad);
                    }
                    //// Use the brush to paint the button's background.
                    Btn.Background = BtnBrush;

                }
                catch (Exception)
                {
                }
            }
            Btn.Tag = dr["MENUID"];
            Btn.Click += btn1_Click;
            Style style = this.FindResource("CircleButton") as Style;
            Btn.Style = style;
            Btn.Width = 85;
            Btn.Height = 85;
            Btn.HorizontalAlignment = HorizontalAlignment.Center;
            Btn.Margin = new Thickness(0,2,0,0.1);
            //an(Btn);
            LB.Foreground = Brushes.White;
            LB.FontWeight = FontWeights.Bold;
            LB.Content = dr["MENUTITLE"];
            LB.HorizontalAlignment = HorizontalAlignment.Center;
            StackPanel stackpanel_Menu = new StackPanel();
            stackpanel_Menu.Children.Add(Btn);
            stackpanel_Menu.Children.Add(LB);
            stackpanel_Menu1.Children.Add(stackpanel_Menu);

所以它向Stackpanel添加了15个按钮,我可以垂直看到它们。当我可以滚动到最后的第15个按钮时,我希望它再次向我显示第一个按钮并继续向下滚动,而不是结束滚动。

1 个答案:

答案 0 :(得分:0)

这在WPF中没有开箱即用

找到第三方控件或编写自己的实现。