私のユーザー インターフェイスでは、ユーザー コントロールの上にタイトルを配置したいことがあります。
将来のローカライズのためにこれらのタイトルを XAML で宣言したいので、データ コンテキストから除外したいと考えています。
データバインディングは、ユーザーコントロールのルートノードに設定されたプロパティからそれらを取得できますか?
問題を次のコード例に要約しました。
using System.Windows;
namespace WpfApplication12
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Person = new Author { Name = "Guge" };
this.DataContext = this;
}
public object Person { get; set; }
}
public class Author
{
public string Name { get; set; }
}
}
と:
<Window x:Class="WpfApplication12.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication12"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type local:Author}">
<Border AutomationProperties.Name="Author" BorderThickness="1" BorderBrush="Black">
<Label Content="{Binding Name}"/>
</Border>
</DataTemplate>
</Window.Resources>
<StackPanel>
<Label x:Name="Position" Content="Author"/>
<ContentControl x:Name="presentation" Content="{Binding Person}"/>
</StackPanel>
実際の問題は、「Position」ラベルの content プロパティでデータバインディングを使用して、DataTemplate の Border の AutomationProperties.Name プロパティから「Author」という単語を取得するにはどうすればよいですか?