在WPF,MVVM中与Row一起编辑DataGrid单元格 [英] Get the DataGrid Cell editing along with Row in WPF, MVVM

查看:159
本文介绍了在WPF,MVVM中与Row一起编辑DataGrid单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用XmlDataProvider填充我的DataGrid控件,我为每列定义了列和XPath。当用户编辑任何单元格以及行详细信息时,我想在我的ViewModel中获取光标。我怎样才能实现这个目标。



请在下面找到我的代码:



Hi,
I am populating my DataGrid control using an XmlDataProvider, I have defined columns along with XPath for each column. I want to get the cursor in my ViewModel when the user edits any cell along with the Row Details. How can I achieve this.

Please find my code below:

dataProvider = new XmlDataProvider();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(@"F:\Work\Samples\WPF\XML Binding Samples\tCustomers2.xml");
dataProvider.Document = doc;
dataProvider.XPath = "DocumentElement";

XAML 







<DataGrid x:Name="dgXml" DataContext="{Binding DataProvider}" ItemsSource="{Binding XPath=tCustomers}" AutoGenerateColumns="False" Grid.Row="1">
    <DataGrid.Columns>
        <DataGridTextColumn IsReadOnly="True" Header="CustomerId" Binding="{Binding XPath=CustomerId/text()}" Width="*"/>
        <DataGridTextColumn Header="Customer Name" Binding="{Binding XPath=CustomerName/text()}" Width="*"/>
         <DataGridTextColumn Header="Customer Address" Binding="{Binding XPath=Address/text()}" Width="*"/>                
     </DataGrid.Columns>
</DataGrid>





XML文件:



XML File:

<NewDataSet>
  <tCustomers>
    <CustomerId>1</CustomerId>
    <CustomerName>Customer1</CustomerName>
    <Address>asdf</Address>
    <BranchId>1</BranchId>
  </tCustomers>
  <tCustomers>
    <CustomerId>2</CustomerId>
    <CustomerName>Customer2</CustomerName>
    <Address>kgh</Address>
    <BranchId>1</BranchId>
  </tCustomers>
  <tCustomers>
    <CustomerId>3</CustomerId>
    <CustomerName>Customer3</CustomerName>
    <Address>kgh</Address>
    <BranchId>1</BranchId>
  </tCustomers>
  <tBranches>
    <BranchId>1</BranchId>
    <BranchName>Branch1</BranchName>
    <Address>Hydrebad</Address>
  </tBranches>
  <tBranches>
    <BranchId>2</BranchId>
    <BranchName>Branch2</BranchName>
    <Address>Bangalore</Address>
  </tBranches>
</NewDataSet>

推荐答案

这篇关于在WPF,MVVM中与Row一起编辑DataGrid单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆