在运行时为DataGridCell应用模板

时间:2019-07-08 12:54:48

标签: wpf datagrid

我想在运行时将DataTemplate应用于wpf DatagridCell。

使用以下代码,在运行时出现组合框,其中没有数据。

<DataTemplate x:Key="cmbTemplate">
                <ComboBox x:Name="cmbPicklist" ItemsSource="{Binding Picklist}" SelectedItem="{Binding PicklistSelectedItem}"/>
            </DataTemplate>


 <Style x:Key="MyContentStyle" TargetType="DataGridCell">          
                <Style.Triggers>
                    <DataTrigger Binding="{Binding HasPicklist}" Value="True">
                        <Setter Property="ContentTemplate" Value="{StaticResource cmbTemplate}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

在后面的代码中:

Dim oDataGridCell As DataGridCell = CType(grd_elements.Columns(0).GetCellContent(grd_elements.Items(1))?.Parent, DataGridCell)
            oDataGridCell.Style = CType(oUcDatagrid.grd_layout_main.FindResource("MyContentStyle"), Style)

我想在组合框中显示数据。谁能告诉我做错了什么以及如何纠正它才能使它正常工作。

0 个答案:

没有答案
相关问题