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";
}
}
<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";
}
}
相关文章推荐
- WPF绑定各种数据源之xml数据源
- WPF下ListView 绑定xml数据源的方案
- WPF绑定XML数据源
- WPF绑定各种数据源之xml数据源
- WPF数据绑定到各种数据源系列(XML数据源)
- WPF中控件绑定XML文件,实现修改XML文件即可以改变程序控件内容
- [原创]WPF中ListView绑定数据源后居中显示
- ASP.NET实现TreeView的XML数据源绑定实例代码
- WPF xml的绑定
- WPF绑定各种数据源之object数据源
- 绑定任意格式的XML文档到WPF的TreeView
- WPF DevExpress Chart控件 界面绑定数据源,不通过C#代码进行绑定
- 控件数据绑定--Xml做数据源
- EXT.NET 绑定XML数据源
- TreeView的数据源绑定—采用XML作为数据源,实现对treeview进行增删改查,之后回写XML文档
- WebDataTree 使用XML做数据源绑定数据
- WPF之Menu绑定XML
- WPF XAML绑定xml
- Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定之二:使用外部URL的XML文件)
- 菜鸟做wpf绑定xml使遇到很多问题,跪求解