如何在 ControlTemplate 中使用一些 UI 元素设置 Grid 对象?我尝试使用此代码,但我不明白如何将 Grid 对象设置为 FrameworkElementFactory 对象。谢谢
ControlTemplate CellControlTemplate = new ControlTemplate(); // my control template
Grid CellGrid = new Grid(); // my grid (I want add it to my control template
FrameworkElementFactory root = new FrameworkElementFactory(typeof(Grid));
// ???
CellControlTemplate.VisualTree = root;
我需要它来在后面的代码中替换我的 xaml 设计样式:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="PStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Grid Margin="4">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"
FontWeight="DemiBold"
FontSize="18"
VerticalAlignment="Center"
Text="{Binding Path=DataItem.DINAMIC_COLUMN}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我必须这样做,因为我想在运行时从代码中更改文本框的绑定路径。你知道其他方法吗?谢谢。