WPF DataGridComboboxColumn,静态列表仅在编辑模式下显示

时间:2015-07-24 15:58:21

标签: .net wpf vb.net

所以,我有一个DataGridComboBoxColumn,其itemssource设置为一个静态列表。

DatagridComboboxColumn:

 <DataGridComboBoxColumn Header="Prioridad" Width="1*" SelectedValueBinding="{Binding SelectedPriorityLevel}"
                          DisplayMemberPath="Key"  SelectedValuePath="Value"        ItemsSource="{StaticResource arrList}">


            </DataGridComboBoxColumn>

静态资源:

    <Window.Resources>
    <col:ArrayList x:Key="arrList">
        <col:DictionaryEntry Key="A" Value="1"/>
        <col:DictionaryEntry Key="M" Value="2"/>
        <col:DictionaryEntry Key="B" Value="3"/>
    </col:ArrayList>
</Window.Resources>

并将绑定设置为具有Enum

的字段
Public Enum ActionPlanPriorityLevels
Alta = 1
Media = 2
Baja = 3

End Enum

我遇到的问题是组合框仅出于某种原因显示在编辑模式中。

Showing on editing mode Not Showing

但所选值未显示

我想念的是什么?

2 个答案:

答案 0 :(得分:1)

所以我做了以下操作,它似乎对我很好

<Window x:Class="Tester.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <collections:ArrayList x:Key="arrList">
        <collections:DictionaryEntry Key="A" Value="1"/>
        <collections:DictionaryEntry Key="M" Value="2"/>
        <collections:DictionaryEntry Key="B" Value="3"/>
    </collections:ArrayList>
</Window.Resources>
<Grid>
    <StackPanel>
        <DataGrid ItemsSource="{Binding GridItems}" x:Name="dataGrid" AutoGenerateColumns="false">
            <DataGrid.Columns>
                <DataGridComboBoxColumn Header="Prioridad" Width="1*" SelectedValueBinding="{Binding SelectedPriorityLevel}"
                          DisplayMemberPath="Key"  SelectedValuePath="Value" ItemsSource="{StaticResource arrList}">
                </DataGridComboBoxColumn>
            </DataGrid.Columns>
        </DataGrid>
    </StackPanel>
</Grid>

    /// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private MainWindowViewModel _viewmodel;
    public MainWindow()
    {
        _viewmodel = new MainWindowViewModel();
        _viewmodel.GridItems.Add(new GridItemViewModel());
        _viewmodel.GridItems.Add(new GridItemViewModel());

        this.DataContext = _viewmodel;
        InitializeComponent();
    }
}

public class MainWindowViewModel
{
    private ObservableCollection<GridItemViewModel> _gridItems = new ObservableCollection<GridItemViewModel>();
    public ObservableCollection<GridItemViewModel> GridItems
    {
        get { return _gridItems; }
        set { _gridItems = value; }
    }
}

public class GridItemViewModel
{
    private string _selectedPriorityLevel;
    public string SelectedPriorityLevel
    {
        get { return _selectedPriorityLevel; }
        set { _selectedPriorityLevel = value; }
    }
}

答案 1 :(得分:0)

尝试添加所选值的属性

 SelectedValueBinding

https://stackoverflow.com/a/3270745/2470362