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";
}
}