将DataGridComboBoxColumn绑定到枚举值

时间:2017-12-28 18:04:41

标签: wpf binding datagridviewcolumn

我正在尝试将枚举值绑定到DataGridComboBoxColumn,但它不起作用。在我的情况下,我想将枚举CamSegmentType绑定到DataGridComboBoxColumn。似乎无法找到枚举eCamType。我不知道出了什么问题。

XAML:

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    Title="MainWindow" Height="350" Width="825">

<Window.Resources>
    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="GetEnumValues">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="local:eCamType"/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Window.Resources>

<Grid>
    <DataGrid Name="dgCamSegements" AutoGenerateColumns="False" Margin="10,180,10,10">
        <DataGrid.Columns>
            <DataGridComboBoxColumn Header="Value" ItemsSource="{Binding Source={StaticResource GetEnumValues}}" SelectedValueBinding="{Binding CamSegmentType}" />
            <DataGridTextColumn Header="Leitwert" Binding="{Binding MasterPosStart}" />
            <DataGridTextColumn Header="Folgewert" Binding="{Binding SlavePosStart}" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

代码:

    namespace WpfApp1
{


      public partial class MainWindow : Window
    {
        public enum eCamType { Gerade, Polynom, };
        public class CamSegment
        {
            public eCamType CamSegmentType { get; set; }
            public double MasterPosStart { get; set; }
            public double SlavePosStart { get; set; }
        }


        public MainWindow()
        {
            InitializeComponent();
...

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

添加您的代码:

Mode=TwoWay, UpdateSourceTrigger=PropertyChanged in 
SelectedValueBinding DataGridComboBoxColumn