在 ControlTemplate 中访问 Grid
Accessing Grid inside ControlTemplate
我有 ControlTemplate 里面有 Grid。但是我找不到任何方法在包含我的模板的控件中访问此网格:(
<Window.Resources>
<ControlTemplate TargetType="ContentControl" x:Key="CertificatesTable">
<Grid Margin="5">
...
</Grid>
</ControlTemplate>
</Window.Resources>
...
<Border Grid.Row="2" Grid.ColumnSpan="100" BorderThickness="1,0,1,1" BorderBrush="#99000000">
<ContentControl Name="Certificates1" Template="{StaticResource CertificatesTable}"/>
</Border>
<Border Grid.Row="4" Grid.ColumnSpan="100" BorderThickness="1,0,1,1" BorderBrush="#99000000">
<ContentControl Name="Certificates2" Template="{StaticResource CertificatesTable}"/>
</Border>
<Border Grid.Row="6" Grid.ColumnSpan="100" BorderThickness="1,0,1,1" BorderBrush="#99000000">
<ContentControl Name="Certificates3" Template="{StaticResource CertificatesTable}"/>
</Border>
...
Pomah 欢迎来到 stack-overflow。
这是如何在代码端访问或获取网格详细信息的简单代码。
<Window.Resources>
<ControlTemplate x:Name="myControl" TargetType="ContentControl" x:Key="CertificatesTable">
<Grid Margin="5" x:Name="grv">
...
</Grid>
</ControlTemplate>
</Window.Resources>
访问网格详细信息的 C# 代码-
ar template = myControl.Template;
var myControl = (Grid)template.FindName("grv", myControl);
我有 ControlTemplate 里面有 Grid。但是我找不到任何方法在包含我的模板的控件中访问此网格:(
<Window.Resources>
<ControlTemplate TargetType="ContentControl" x:Key="CertificatesTable">
<Grid Margin="5">
...
</Grid>
</ControlTemplate>
</Window.Resources>
...
<Border Grid.Row="2" Grid.ColumnSpan="100" BorderThickness="1,0,1,1" BorderBrush="#99000000">
<ContentControl Name="Certificates1" Template="{StaticResource CertificatesTable}"/>
</Border>
<Border Grid.Row="4" Grid.ColumnSpan="100" BorderThickness="1,0,1,1" BorderBrush="#99000000">
<ContentControl Name="Certificates2" Template="{StaticResource CertificatesTable}"/>
</Border>
<Border Grid.Row="6" Grid.ColumnSpan="100" BorderThickness="1,0,1,1" BorderBrush="#99000000">
<ContentControl Name="Certificates3" Template="{StaticResource CertificatesTable}"/>
</Border>
...
Pomah 欢迎来到 stack-overflow。
这是如何在代码端访问或获取网格详细信息的简单代码。
<Window.Resources>
<ControlTemplate x:Name="myControl" TargetType="ContentControl" x:Key="CertificatesTable">
<Grid Margin="5" x:Name="grv">
...
</Grid>
</ControlTemplate>
</Window.Resources>
访问网格详细信息的 C# 代码-
ar template = myControl.Template;
var myControl = (Grid)template.FindName("grv", myControl);