0

几天前我在一篇文章中看到了这个例子。

    <Window x:Class="DataGridWithMultipleTypesPerColumn.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
    <DataGrid ItemsSource="{Binding ControlTypes}"
              AutoGenerateColumns="False">
        <DataGrid.Columns>
        <DataGridTextColumn Header="Control Type" Binding="{Binding}"/>
            <DataGridTemplateColumn Header="Actual Control">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ContentControl>
                            <ContentControl.Style>
                                <Style TargetType="ContentControl">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding}" Value="TextBox">
                                            <Setter Property="ContentTemplate">
                                                <Setter.Value>
                                                    <DataTemplate>
                                                        <TextBox Text="Default Text"/>
                                                    </DataTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding}" Value="CheckBox">
                                            <Setter Property="ContentTemplate">
                                                <Setter.Value>
                                                    <DataTemplate>
                                                        <CheckBox Content="Check Box"/>
                                                    </DataTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding}" Value="Button">
                                            <Setter Property="ContentTemplate">
                                                <Setter.Value>
                                                    <DataTemplate>
                                                        <Button Content="Button"/>
                                                    </DataTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </ContentControl.Style>
                        </ContentControl>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
</Grid>

我想获取此控件的值,如果控件是 Chekcbox,我需要该值,我正在尝试使用 foreach,但我没有为每个项目使用正确的演员表。

请问我需要你的帮助,我该怎么办?

谢谢 !

4

0 回答 0