【发布时间】:2018-03-25 18:03:30
【问题描述】:
所以当我双击一个项目来编辑我的数据网格中的值时,我不断收到错误消息。
''EditItem' 不允许用于此视图。'
我以前从未遇到过这种情况,所以我不确定该如何处理。 是什么导致了这个问题以及处理这个问题的正确方法是什么,所以我知道将来如何处理它。 我尝试在 Google 上查看它,但它都有列表要做,因为我没有使用列表,所以我看不到与我的应用程序的连接。
XAML
<DataGrid Name="dgItems">
<DataGrid.Columns>
<DataGridTextColumn Header="Property" Binding="{Binding Property}" />
<DataGridTextColumn Header="Value" Binding="{Binding Value}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
CS
private void btnStart_Click(object sender, RoutedEventArgs e)
{
string path = "";
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Properties | *.properties";
if (ofd.ShowDialog() == true)
{
path = ofd.FileName;
}
using (StreamReader sr = new StreamReader(path))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (!line.StartsWith("#"))
{
string[] lines = line.Split('=');
string property = lines[0];
string value = lines[1];
this.dgItems.Items.Add(new ServerProperties { Property = property, Value = value });
Debug.Print($"Property: {property} Value: {value}");
}
}
}
}
获取和设置值的我的类
public class ServerProperties
{
public string Property { get; set; }
public string Value { get; set; }
}
【问题讨论】: