[英]Programmatically get properties of UserControl.Grid?
I have created a simple WPF test program, based on what Visual Studio gives me when I add a UserControl1.xaml to my project. 我创建了一个简单的WPF测试程序,该程序基于Visual Studio在向用户项目添加UserControl1.xaml时提供的功能。 In XAML it appears that the blank "background canvas" is of type Grid.
在XAML中,似乎空白的“背景画布”的类型为Grid。
When I create an instance of UserControl1, is there any possibility to programmatically access the underlying Grid instance (so I can change the background color)? 创建UserControl1的实例时,是否可以通过编程方式访问基础的Grid实例(因此我可以更改背景颜色)?
Give the grid a name: 为网格命名:
<UserControl>
<Grid x:Name="YourFancyGrid">
<!-- Grid stuff -->
</Grid>
</UserControl>
Then you can access it from the C# side: 然后,您可以从C#端访问它:
YourFancyGrid.Background = new SolidColorBrush(Colors.Red);
由于UserControl是ContentControl,因此网格位于Content属性中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.