WPF XAML绑定xml

前端之家收集整理的这篇文章主要介绍了WPF XAML绑定xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

WPF XAML绑定XML

1.PackageConfig.xml文件

<?xml version="1.0" encoding="utf-8" ?>
<Mysoft.Config>
  <PackageCollection>
    <PackageVersionName>123111</PackageVersionName>
  </PackageCollection>
</Mysoft.Config>

2.PackageModifyUI.xaml文件

<Window x:Class="UpgradeBuilder.UI.PackageModifyUI"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="http://schemas.microsoft.com/wpf/2008/toolkit"
        xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:ui="clr-namespace:UpgradeBuilder.UI"
        Title="更新包版本管理" Top="200" Left="400" Height="400" Width="500">
    <!--绑定-->
    <Window.Resources>
        <XmlDataProvider x:Key="AllItem" Source="../PackageConfig.xml"  XPath="Mysoft.Config"/>
    </Window.Resources>
    <Grid Margin="5" >
        <Grid.RowDefinitions>
            <RowDefinition Height="70"/>
            <RowDefinition Height="240"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" DataContext="{Binding Source={StaticResource AllItem},XPath=PackageCollection}">
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="30*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label Content="更新包版本:" Grid.Row="0" Grid.Column="0" Margin="2,2,2"/>
            <TextBox Name="PackageVersionNameBox" Grid.Row="0" Grid.Column="1" Height="25" Margin="2,2" Text="{Binding XPath=PackageVersionName}" IsReadOnly="False"/>
        </Grid>
    </Grid>
</Window>

猜你在找的XML相关文章