wpf 动态添加控件解决思路
wpf 动态添加控件
最近要用WPF开发,本来以为都是C# ,winform转过来应该不难,结果处处碰壁
我在 tabControl 中动态添加了些子项(items),我想在其子项中动态的添加些控件,要怎么做呢?怎么处理它们的位置。
Controls 在WPF里找不到
网上说的 Children.add 我也只有在 canvas 中找到。
------解决方案--------------------
内容控件都有Children.add(你的自定义控件名) 在你的tabControl 里面的某个项里面添加grid 然后grid .Children.add 就可以了
------解决方案--------------------
这样就可以了.可以把tempGrid换成UserControl,自己已经写好的界面
最近要用WPF开发,本来以为都是C# ,winform转过来应该不难,结果处处碰壁
我在 tabControl 中动态添加了些子项(items),我想在其子项中动态的添加些控件,要怎么做呢?怎么处理它们的位置。
Controls 在WPF里找不到
网上说的 Children.add 我也只有在 canvas 中找到。
------解决方案--------------------
内容控件都有Children.add(你的自定义控件名) 在你的tabControl 里面的某个项里面添加grid 然后grid .Children.add 就可以了
------解决方案--------------------
TabItem temptb = new TabItem();
LinearGradientBrush _brush = new LinearGradientBrush();
Color sColor = Color.FromArgb(255, 122, 210, 231);
Color eColor = Color.FromArgb(255, 14, 75, 133);
_brush.StartPoint = new Point(0.5, 0);
_brush.EndPoint = new Point(0.5, 1);
_brush.GradientStops.Add(new GradientStop(sColor, 0.0));
_brush.GradientStops.Add(new GradientStop(eColor, 1.0));
temptb.Width = 70;
temptb.Header = "111";
temptb.Background = _brush;
Grid tempGrid = new Grid();
tempGrid.Background =new SolidColorBrush(Colors.Yellow);
temptb.Content = tempGrid;
tabControl1.Items.Add(temptb);
这样就可以了.可以把tempGrid换成UserControl,自己已经写好的界面