如何使用按钮在WPF中滚动堆栈面板上的项目 [英] How to scroll the items at stack panel in WPF using buttons
问题描述
大家好。
我有一个要求,比如我需要将一些按钮绑定到堆叠面板,如果我点击向下按钮,我需要在下面放两个按钮我需要显示哪些项目也是低于默认的来源项目,如同向上按钮一样。
我尝试过:
我只是以编程方式将项目绑定到堆栈面板。
if(ds!= null&& ds.Tables [0]。 Rows.Count> 0)
{
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 id = ds.Tables [0] .Rows [i] [0] .ToString();
string status = ds.Tables [0] .Rows [i] [1] .To String();
if(status ==Pending)
{
Button [i] .Background = Brushes.Red;
}
if(status ==Cancelled)
{
Button [i] .Background = Brushes .Orange;
}
if(status ==Completed)
{
Button [i] .Background = Brushes.Green;
}
// string s1 = ds.Tables [0] .Rows [i] [1] .ToString();
Button [i] .Content = id;
Button [i] .Tag = id;
Button [i] .Click + = btn_Click;
按钮[i] .Height = 41;
Button [i] .Width = 120;
Button [i] .Foreground = Brushes.White;
Button [i] .FontWeight = FontWeights.Bold;
Button [i] .FontStyle = FontStyles.Italic;
Button [i] .FontSize = 14;
stackPanel1.Children.Add(Button [i ]);
}
catch(例外情况)
{
}
}
}
private void btnup_Click(object sender,RoutedEventArgs e)
{
//我该怎么办
}
private void btndown_Click(对象发送者) ,RoutedEventArgs e)
{
//我该怎么办
}
WPF工具包中的手风琴 [ ^ 一>
Hi, all.
I have a requirement like I need to bind some buttons to stack panel and I need to put two buttons below if I click on Down button I need to show the items which are below the default came items like the same for up button also.
What I have tried:
I just bind items to stack panel programmatically.
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
Button[] Button = new Button[ds.Tables[0].Rows.Count];
try
{
Button[i] = new Button();
string id = ds.Tables[0].Rows[i][0].ToString();
string status = ds.Tables[0].Rows[i][1].ToString();
if (status == "Pending")
{
Button[i].Background = Brushes.Red;
}
if (status == "Cancelled")
{
Button[i].Background = Brushes.Orange;
}
if (status == "Completed")
{
Button[i].Background = Brushes.Green;
}
// string s1 = ds.Tables[0].Rows[i][1].ToString();
Button[i].Content = id;
Button[i].Tag = id;
Button[i].Click += btn_Click;
Button[i].Height = 41;
Button[i].Width = 120;
Button[i].Foreground = Brushes.White;
Button[i].FontWeight = FontWeights.Bold;
Button[i].FontStyle = FontStyles.Italic;
Button[i].FontSize = 14;
stackPanel1.Children.Add(Button[i]);
}
catch (Exception ex)
{
}
}
}
private void btnup_Click(object sender, RoutedEventArgs e)
{
//what should i do here
}
private void btndown_Click(object sender, RoutedEventArgs e)
{
//what should i do here
}
Hi, I think you are looking for a control like Accordition, So refer below link, it might be a solution for you.
Accordion in WPF Toolkit[^]
这篇关于如何使用按钮在WPF中滚动堆栈面板上的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!