0

It seems an easy problem but I can't figure out. The scenery:

In C#/WPF/MVVM, I have a DataGrid showing some data. One field (a cell of a row) is an integer value. Now I need to display a ComboBox for that cell showing "local" if the value is 0, "Network" if the value is 1 or greater. How can I bind this?

Thank you.

4

1 回答 1

0

您应该可以使用它DataGridTemplateColumn Template来执行此操作。

下面是一个帮助示例:

    <DataGrid Grid.Row="0"  
              AutoGenerateColumns="False" Height="Auto" 
              SelectionMode="Single" ItemsSource="{Binding MyViewItemModels}"  
                  RowDetailsVisibilityMode="Collapsed" HeadersVisibility="Column" CanUserAddRows="False" 
                  GridLinesVisibility="None" AlternationCount="2" AlternatingRowBackground="GhostWhite" Background="White">

        <DataGrid.Columns>

            <DataGridTemplateColumn IsReadOnly="True" MinWidth="50" Width="70" >
                <DataGridTemplateColumn.Header>
                    <Border Height="30">
                        <Label Content="My Name"/>
                    </Border>
                </DataGridTemplateColumn.Header>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ComboBox Height="16" ItemsSource="{Binding MyItems, Mode=OneWay}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
于 2013-04-16T10:12:48.900 回答