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;
但是我上面写的实现不了,请教该怎么写? 展开
我想把用户控件放到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;
}
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询