0
ControlTemplateのUI要素でGridオブジェクトを設定するにはどうすればよいですか?私はこのコードを使用しようとしますが、私はGridElementFactoryオブジェクトにGridオブジェクトを設定する方法を理解していません。私はコードから実行時にテキストボックスのための結合パスを変更したいので、私は、それを行う必要がありますControlTemplateをコードで設定する[WPF]
<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>
:ありがとう
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に設計されたスタイルを置き換えるためにそれを必要とします。あなたは他の方法を知っていますか?ありがとう。
var grid = new FrameworkElementFactory(typeof(Grid));
// assign template to grid
CellControlTemplate.VisualTree = grid;
// define grid's rows
var r = new FrameworkElementFactory(typeof(RowDefinition));
grid.AppendChild(r);
// define grid's columns
var c = new FrameworkElementFactory(typeof(ColumnDefinition));
grid.AppendChild(c);
//... etc
おかげで、すべて:ここ
あなたはこれで何を達成しようとしていますか?また、グリッドはコントロールではなく、コントロールを格納するだけで、リストボックスにDataTemplateを適用したいと思うかもしれません。 – Machinarius
私はスタイルを持っています。このスタイルにはコントロールテンプレートが含まれています。私はいくつかのコントロールを持っています、そして、私はこのコントロールテンプレートに追加します。これらのコントロールをグリッドに入れ、このグリッドをコントロールテンプレートに設定しようとします。 – Dmitriy