C# wpf 放在StackPanel中的确定位置

StackPanelpanel=newStackPanel();panel.Orientation=Orientation.Horizontal;………………panel.... StackPanel panel = new StackPanel();panel.Orientation = Orientation.Horizontal; ……………… panel.Children.Add(s); if (cc == 0) { s.HorizontalAlignment = HorizontalAlignment.Left; } else { s.HorizontalAlignment = HorizontalAlignment.Right; }
我想把用户控件放到panel中,第一个S 就放在panel的左边,第二个就放在panel 的右边, 相当于winform里面的 Button b1 = new Button(); Button b2 = new Button();
this.Panel.Controls.Add(b1); b1.Dock = DockStyle.Left; this.Panel.Controls.Add(b2); b2.Dock = DockStyle.Right;
但是我上面写的实现不了,请教该怎么写?
展开
 我来答
匿名用户
2013-05-21
展开全部
Button btn1 = new Button() { Name = "btn1", Content = "btn1", Width = 150, Height = 150 };
Button btn2 = new Button() { Name = "btn2", Content = "btn2", Width = 150, Height = 150 }; this.RegisterName("btn1", btn1);
this.RegisterName("btn2", btn2); stackPanel1.Children.Add(btn1);
stackPanel1.Children.Add(btn2);
Button _btn1 = (Button)stackPanel1.FindName("btn1");
Button _btn2 = (Button)stackPanel1.FindName("btn2");
int cc =0;
if (cc==0)
{
_btn1.HorizontalAlignment = HorizontalAlignment.Left;
_btn2.HorizontalAlignment = HorizontalAlignment.Right;
}
else
{
_btn1.HorizontalAlignment = HorizontalAlignment.Right;
_btn2.HorizontalAlignment = HorizontalAlignment.Left;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式