Вы можете привязать данные к статическим свойствам, включая настройки приложения, непосредственно в XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:WpfApplication1"
xmlns:p="clr-namespace:WpfApplication1.Properties"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<TextBlock Text="{Binding Source={x:Static l:MainWindow.AssemblyTitle}}"/>
<TextBlock Text="{Binding Source={x:Static p:Settings.Default}, Path=VersionNumber}"/>
</StackPanel>
</Grid>
</Window>
… где WpfApplication1
- ваше пространство имен, а VersionNumber
- строка, определенная в настройках приложения.
Чтобы получить заголовок сборки, нам понадобится немного кода в классе MainWindow
:
public static string AssemblyTitle
{
get
{
return Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)
.Cast<AssemblyTitleAttribute>()
.Select(a => a.Title)
.FirstOrDefault();
}
}
P.S. Вы не можете присвоить одно и то же имя двум элементам.