简体   繁体   English

WPF StackPanel项目应重复自己

[英]WPF StackPanel Items should repeat themselves

I am adding buttons to the Stack-panel on run time in C# WPF. 我在C#WPF中在运行时向堆栈面板添加按钮。 What i want is the when i am scrolling through the Stack panel items once i reach the last time i want it to show the first item after the last one so it kinds of keeps repeating the list. 我想要的是当我到达最后一次时要滚动浏览“堆栈”面板中的项目时,我希望它显示最后一个项目之后的第一个项目,因此它会不断重复该列表。

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

                        <StackPanel x:Name="stackpanel_Menu1">

                        </StackPanel>
                </ScrollViewer>

and this is the Code for creating the buttons. 这是创建按钮的代码。

 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);

so it adds 15 buttons to the Stackpanel and i can see them vertically. 因此它向Stackpanel添加了15个按钮,我可以垂直看到它们。 When i can scrolling to the last 15th button i want it to show me the first button again and keep scrolling down, rather then ending the scroll. 当我可以滚动到最后一个第15个按钮时,我希望它再次向我显示第一个按钮,并继续向下滚动,而不是结束滚动。

This is not available out of the box in WPF 这在WPF中不可用

Either find a 3rd party control or write your own implementation. 查找第三方控件或编写您自己的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM