C# 如何在DataGrid中允许单元格编辑

C# 如何在DataGrid中允许单元格编辑,c#,wpf,datagrid,C#,Wpf,Datagrid,我有一个由XML文件填充的数据网格。 文件中的所有值都显示良好。 问题是我在DataGrid中添加了一些其他列,我需要让用户 编辑这些列的内容。 当我尝试编辑内容时,没有显示任何内容,它总是空白的 以下是我的DataGrid Xaml: <DataGrid ItemsSource="{Binding Path=Elements[Parameter]}" AutoGenerateColumns="False" He

我有一个由XML文件填充的数据网格。 文件中的所有值都显示良好。 问题是我在DataGrid中添加了一些其他列,我需要让用户 编辑这些列的内容。 当我尝试编辑内容时,没有显示任何内容,它总是空白的

以下是我的DataGrid Xaml:

  <DataGrid 
        ItemsSource="{Binding Path=Elements[Parameter]}"
        AutoGenerateColumns="False" Height="Auto" 
        Name="DataGridParamScenarios" Grid.Row="1" MaxHeight ="250"
        Block.TextAlignment="Center" HorizontalAlignment =" Stretch"   HorizontalContentAlignment ="Stretch"
        Background="WhiteSmoke" RowBackground="LightYellow"
        AlternatingRowBackground="LightBlue" RowHeight="30" CanUserAddRows="False"
        SelectedItem="{Binding Path=SelectedParameter, Mode=TwoWay}"
        ScrollViewer.VerticalScrollBarVisibility="Visible" 
        CurrentCellChanged ="DataGridParamScenarios_CurrentCellChanged">

           <DataGrid.Columns>
               
              <DataGridTextColumn 
                Header="Name" IsReadOnly ="True"
                Binding="{Binding Path=Element[Name].Value}" Width ="*"/>
              <DataGridTextColumn 
                Header="Category" 
                Binding="{Binding Path=Element[Category].Value}" Width ="Auto" IsReadOnly="True"/>
              <DataGridTextColumn 
                Header="Value" 
                Binding="{Binding Path=Element[Value].Value}" Width ="*" IsReadOnly="False"/>
              <DataGridTextColumn 
                Header="Unit" 
                Binding="{Binding Path=Element[Unit].Value}" Width ="*" IsReadOnly="False" />
              <DataGridTextColumn 
                Header="Min" Width ="*" IsReadOnly="False"/>
              <DataGridTextColumn 
                Header="Max" Width ="*" IsReadOnly="False"/>
                    
                </DataGrid.Columns>

        </DataGrid>

WPF不能直接绑定到局部变量。您必须在属性中包装
MinValue
MaxValue

要绑定的DataGridTextColumns链接到什么?我看到前四个有绑定,为什么不把后两个链接到一个绑定上呢?如果你能看到我修改了它,但是什么也没发生
 <DataGridTextColumn 
                Header="Min" 
                Binding="{Binding Path= MinValue}"
                Width ="*" IsReadOnly="False"/>
 <DataGridTextColumn 
                Header="Max" 
                Binding="{Binding Path= MaxValue}"
                Width ="*" IsReadOnly="False"/>
 public partial class Scenarios : Window
{

    string MinValue = "0";
    string MaxValue = "20";
 public Scenarios()
    {
        InitializeComponent();
        var xml = XDocument.Load(XmlPath).Root;
        DataGridParamScenarios.DataContext = xml;
    }
}