最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wpf - How to fill a Combobox inside a DataGrid with the Content of a DataTable - Stack Overflow

programmeradmin1浏览0评论

I have a DATAGRID and fill it with a DataTable. The table has columns that contain an ID (ValidationID) on a DataTable PTable with different values that I want to display as a combo box in the VALIDATION column. Furthermore, the combo box should not be displayed when the CheckBox DDL is selected.

Everything works, except that I cannot fill the combo box.

...
<Window.Resources>
    <CollectionViewSource x:Key="PTable" Source="{Binding PlausiTable.DefaultView}" />
</Window.Resources>

<DataGridTemplateColumn Header="VALIDATION">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate >
            <ContentControl x:Name="content" Content="{Binding}" >
            </ContentControl>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding DROPDOWN}" Value="0">
                    <Setter TargetName="content" Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <ComboBox x:Name="ddl_Plausi" ItemsSource="{Binding Source={StaticResource PTable}}" 
                                    DisplayMemberPath="ID" 
                                    SelectedItem="{Binding ValidationCheckID, Mode=TwoWay}"
                                    SelectedValuePath="NAME" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding DROPDOWN}" Value="1">
                    <Setter TargetName="content" Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <ComboBox Visibility="Hidden" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="Background" 
                Value="{StaticResource clBr}" />
        </Style>
    </DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn>
...

No matter what I try, the ComboBox remains empty. All other columns work in this way without any problems. Screenshot

发布评论

评论列表(0)

  1. 暂无评论