您的位置:首页 > 其它

WPF绑定xml数据源

2016-11-23 10:00 549 查看
1.界面

<UserControl x:Class="HKDCMS.Client.Demo.UIViews.UIControls.AboutUsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
mc:Ignorable="d"
Background="White"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.Resources>
<XmlDataProvider x:Key="AllItem" Source="AboutUS.xml" XPath="AboutUS"/>
</Grid.Resources>
<Grid DataContext="{Binding Source={StaticResource AllItem}, XPath=PackageCollection}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding XPath=PackageVersionTitle}" FontSize="18" Margin="2" Grid.Row="0"></TextBlock>
<TextBox TextWrapping="Wrap" AcceptsReturn="True" Name="PackageVersionNameBox"
Text="{Binding XPath=PackageVersionName}" IsReadOnly="True" Grid.Row="1" Margin="5"/>
</Grid>
</Grid>
</UserControl>

2.后台代码

public partial class AboutUsControl : UserControl
{
public AboutUsControl()
{
InitializeComponent();
XmlDocument doc = new XmlDocument();
doc.Load("AboutUS.xml");
XmlDataProvider provider = new XmlDataProvider();
provider.Document = doc;
provider.XPath = @"/Note/Body";

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: