简体   繁体   中英

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 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. 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.

在此处输入图片说明

<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. 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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