如何在单击按钮的同时上下移动堆栈面板中的项目 [英] How to move items in stack panel up and down while clicking on buttons
问题描述
嗨所有
我在加载事件中绑定了堆栈面板我在该面板中有50个项目我可以看到前10个项目我需要在点击这些按钮时按下两个按钮上下按钮我需要移动这些物品
我尝试过:
我只是将一些项目绑定到堆栈面板
for(int i = 0; i< = ds.Tables [0] .Rows.Count - 1; i ++)
{
Button [] Button = new Button [ds.Tables [0] .Rows.Count];
Button [i] = new Button();
string s2 = ds.Tables [0] .Rows [i] [0] .ToString();
string status = ds.Tables [0] .Rows [i] [ 1] .ToString();
Button [i] .Content = s2;
Button [i] .Tag = s2;
Button [i]。点击+ = btn_Click;
stackPanel1.Children.Add(Button [i]);
}
private void btnup_Click(object sender,RoutedEventArgs e)
{
}
private void btndown_Click(object sender,RoutedEventArgs e)
{
}
我应该怎么做这些点击事件请帮助我..
hi all
I bound the stack panel in load event I have 50 items in that panel first 10 items are visible to me I need to put two buttons up and down buttons while clicking on those buttons I need to move those items
What I have tried:
I just bind some items to stack panel
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
Button[] Button = new Button[ds.Tables[0].Rows.Count];
Button[i] = new Button();
string s2 = ds.Tables[0].Rows[i][0].ToString();
string status = ds.Tables[0].Rows[i][1].ToString();
Button[i].Content = s2;
Button[i].Tag = s2;
Button[i].Click += btn_Click;
stackPanel1.Children.Add(Button[i]);
}
private void btnup_Click(object sender, RoutedEventArgs e)
{
}
private void btndown_Click(object sender, RoutedEventArgs e)
{
}
what should i do in these click events please help me..
推荐答案
最简单的方法是使用 ScrollViewer $在StackPanel周围c $ c>。
例如这里是我的XAML:
The easiest way to do this is to use aScrollViewer
around the StackPanel.
For example here is my XAML:
<window x:class="LayoutWithStackPanel.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<grid>
<grid.rowdefinitions>
<rowdefinition height="Auto" />
<rowdefinition height="*" />
</grid.rowdefinitions>
<stackpanel orientation="Horizontal">
<button content="Create" width="75" click="Button_Click" />
<button content="Up" width="75" click="ButtonUp_Click" />
<button content="Down" width="75" click="ButtonDown_Click" />
</stackpanel>
<scrollviewer grid.row="1" name="SvViewer" verticalscrollbarvisibility="Hidden">
<stackpanel name="StackPanel1" orientation="Vertical">
</stackpanel>
</scrollviewer>
</grid>
</window>
这将创建一个页面,顶部有3个按钮,下面的StackPanel将包含生成的按钮。请注意,我已经隐藏了ScrollViewer的滚动条。
我将您的代码放入Button_Click事件中,以在StackPanel StackPanel1中创建大量控件。
其他两个按钮的事件只包括
This will create a page with 3 buttons arranged along the top and a StackPanel below that will contain the generated buttons. Note that I've hidden the scrollbar for the ScrollViewer.
I placed your code into the Button_Click event to create lots of controls in the StackPanel StackPanel1.
The events for the other two buttons consist simply of
private void ButtonUp_Click(object sender, RoutedEventArgs e)
{
SvViewer.LineUp();
}
private void ButtonDown_Click(object sender, RoutedEventArgs e)
{
SvViewer.LineDown();
}
或
or
private void ButtonUp_Click(object sender, RoutedEventArgs e)
{
SvViewer.PageUp();
}
private void ButtonDown_Click(object sender, RoutedEventArgs e)
{
SvViewer.PageDown();
}
取决于您想要滚动的距离。
depending on how far you want to scroll.
这篇关于如何在单击按钮的同时上下移动堆栈面板中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!