每当更改listview对象的一部分时,如何使用绑定更新Listview中的对象? [英] How do i Update an object in a Listview with a binding whenever part of that listview object is changed?

查看:73
本文介绍了每当更改listview对象的一部分时,如何使用绑定更新Listview中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我对下面的代码有疑问。我有下面的文本框上的绑定,并希望更新xml文件,如果他们更改该文本框中的值。但是,当我去TextChanged事件处理程序时,我意识到我不知道如何附加到
当前选中/更改的对象。 

hello, i have a question about my code below. i have bindings on the Textbox below, and want to update an xml file if they change the value inside that textbox. however, when i go to the TextChanged event handler i realized i don't know how to attach to the currently selected/changed object. 

绑定是一个简单的List< TestXmlClass>我在课堂上设置为

the binding is a simple List<TestXmlClass> which i set in the class as

ServiceDetailsList.ItemSource = xmlList;

ServiceDetailsList.ItemSource = xmlList ;




我希望用xdoc重写文件,无论用户输入什么变化。 

and i want to use xdoc to rewrite the file with whatever change the user input. 

<ListView x:Name="ServiceDetailsList" Margin="305,152,0,-431">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <materialDesign:Card>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=XmlKey, StringFormat= ' {0}: '}" VerticalAlignment="Center" Margin="5"></TextBlock>
                                <TextBox Text="{Binding Path=XmlValue}" VerticalAlignment="Center" Width="500" TextChanged="TextBox_TextChanged"/>
                            </StackPanel>
                    </materialDesign:Card>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

在textchange中我有这个功能:

inside textchange i have this function:

UpdateXMLConfig(TestXMLClass,filePath)所以我尝试过执行

UpdateXMLConfig(TestXMLClass,filePath) so i tried doing

UpdateXMLConfig(发件人为TestXMLClass,filePath)但发送了一个空对象。

UpdateXMLConfig(sender as TestXMLClass,filePath) but that sent a null object.




我也刚刚意识到,任何事情发生变化时都会触发此事件(按一个键然后运行),而 我希望他们在函数运行之前完全输入他们正在改变的内容....我应该使用什么事件处理程序?

I also just realized that this event is fired as soon as ANYTHING changes(press a single key and it runs), whereas  i want them to type out entirely what they are changing before the function is run....what event handler should i use instead?




推荐答案

如果需要,管理员可以随意删除它,我通过执行以下操作修复它。如果这不是实现此目标的标准方式,请告诉我。

admins can feel free to delete this if necessary, i fixed it by doing the following. if this is not the standard way of achieving this please let me know. 

var context = sender as TextBox;
string newValue = context.Text;
var details = context.DataContext;
UpdateXMLConfig(details as TestXMLClass,newValue, "");


这篇关于每当更改listview对象的一部分时,如何使用绑定更新Listview中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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