ScrollViewer如何动态添加控件 50
ScrollViewer太特殊了,不知道怎么添加控件、特别是动态添加,不像别的直接children.add就行,这怎么办?C#语言wpf控件...
ScrollViewer太特殊了,不知道怎么添加控件、特别是动态添加,不像别的直接children.add就行,这怎么办?
C#语言 wpf控件 展开
C#语言 wpf控件 展开
1个回答
2015-08-13 · 知道合伙人软件行家
关注
展开全部
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Grid g = new Grid();
g.HorizontalAlignment = HorizontalAlignment.Stretch;
g.VerticalAlignment = VerticalAlignment.Stretch;
g.Background = Brushes.Blue;
ScrollViewer s = new ScrollViewer();
s.Width = 100;
s.Height = 100;
Label l = new Label();
l.Content = @"wpf 控件内 动态添加 控件";
s.Content = l;
this.AddChild(s);
}
{
Grid g = new Grid();
g.HorizontalAlignment = HorizontalAlignment.Stretch;
g.VerticalAlignment = VerticalAlignment.Stretch;
g.Background = Brushes.Blue;
ScrollViewer s = new ScrollViewer();
s.Width = 100;
s.Height = 100;
Label l = new Label();
l.Content = @"wpf 控件内 动态添加 控件";
s.Content = l;
this.AddChild(s);
}
更多追问追答
追问
我要在ScrollViewer里面添加控件!
追答
ScrollViewer 只能加一个控件,你可以用个stackpanel 这种做容器,然后在容器里加子控件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询