简体   繁体   English

WPF DataGrid XML绑定和1列,每5秒更改一次状态

[英]WPF DataGrid XML Binding and 1 Column for status that changes every 5 seconds

Sorry for the confusing title! 抱歉,标题令人迷惑!

This is my XML file: 这是我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<Clients>
    <Client Name="ATCI-105">
        <IP>10.0.2.105</IP>
        <MAC>00:00:00:00:00:00</MAC>
    </Client>
</Clients>

In my WPF view I have a DataGrid which has a binding to my XmlDataProvider. 在我的WPF视图中,我有一个DataGrid,它具有与XmlDataProvider的绑定。 What I want is when I ping to the Client and receive the response I want it to show in my DataGrid Status Column without adding it to the XML File because I check for the status every 5 seconds. 我想要的是当我对Client ping操作并收到响应时,希望它显示在我的DataGrid状态列中而不将其添加到XML文件中,因为我每5秒检查一次状态。

在此处输入图片说明

<DataGrid Grid.Row="0" x:Name="dgClients" x:FieldModifier="public" ItemsSource="{Binding Path=Elements[Client]}" AutoGenerateColumns="False"
                      HeadersVisibility="Column" GridLinesVisibility="None" AlternatingRowBackground="WhiteSmoke" IsReadOnly="True">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Name" Width="*" Binding="{Binding Path=Attribute[Name].Value}"/>
                    <DataGridTextColumn Header="IP" Width="*" Binding="{Binding Path=Element[IP].Value}"/>
                    <DataGridTextColumn Header="MAC" Width="*" Binding="{Binding Path=Element[MAC].Value}"/>
                    <DataGridTextColumn Header="Status" Width="140"/>
                </DataGrid.Columns>
            </DataGrid>

Is there a good way to this? 有一个好的方法吗? If you didn't understand what I want let me know and I will try to explain more. 如果您不明白我想要什么,请告诉我,我将尽力解释更多。

Greetings, Koen 问候,科恩

If the data for your 'Ping result' column does not come from the XML file... then simply don't display the data from the XML file in that column. 如果“ Ping结果”列的数据不是来自XML文件...,那么就不要在该列中显示XML文件中的数据。 Create a collection of string s or whatever data type that you're using in that column in your view model or code behind and bind to that instead. 在视图模型的该列中创建string s或您正在使用的任何数据类型的集合,或在其后进行代码绑定。

Even better, just read the initial values out of the XML file in code behind and then populate a class that was specifically designed for that purpose. 更好的是,只需在后面的代码中从XML文件中读取初始值,然后填充专门为此目的设计的类。 Add a collection of these class instances that represent the data to your view model or code behind and then just bind to that as normal. 将代表数据的这些类实例的集合添加到视图模型或代码中,然后按常规绑定到该模型。 Updating any part of it will then be a breeze. 更新其中的任何部分将变得轻而易举。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM