I have created a simple WPF test program, based on what Visual Studio gives me when I add a UserControl1.xaml to my project. In XAML it appears that the blank "background canvas" is of type 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)?
Give the grid a name:
<UserControl>
<Grid x:Name="YourFancyGrid">
<!-- Grid stuff -->
</Grid>
</UserControl>
Then you can access it from the C# side:
YourFancyGrid.Background = new SolidColorBrush(Colors.Red);
由于UserControl是ContentControl,因此网格位于Content属性中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.