Application data resource window title bar

I am currently doing it like this:

public MainWindow() { InitializeComponent(); Title = Properties.Resources.WindowName; } 

How to do the same through WPF binding?

EDITOR: It still does not work in XAML.
Environment: VS2010, .NET 4.0, Windows 7.
Playback Stages:
Create a class library ClassLibrary1 with code:

  namespace ClassLibrary1 { static public class Class1 { static public string Something { get { return "something"; } } } } 

Create a Windows WPF application in VS2010.NET 4.0.
Edit the main XAML window:

 <Window x:Class="ahtranslator.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ClassLibrary1="clr-namespace:ClassLibrary1;assembly=ClassLibrary1" Title="{Binding Source={x:Static ClassLibrary1:Class1}, Path=Something}" Height="350" Width="525" Icon="/ahtranslator;component/Icon1.ico" WindowStyle="SingleBorderWindow" ShowInTaskbar="False" DataContext="{Binding}"> 

...

Compilation Error Message:
MainWindow.xaml (7,130): error MC3029: member of ClassLibrary1: Class1 is invalid because it does not have a qualification type name.

Also did I find this My.Resources section in WPF XAML? . And everything seems to work, but it is not.

Microsoft does not provide a description for this error message. Just another topic in the help forum http://social.msdn.microsoft.com/Forums/en/wpf/thread/4fe7d58d-785f-434c-bef3-31bd9e400691 , which also does not help.

+8
c # data-binding wpf xaml
source share
4 answers

In code, it will look like this:

 Binding titleBinding = new Binding("WindowName"); titleBinding.Source = Properties.Resources; this.SetBinding(Window.Title, titleBinding); 

This makes sense only if changes can take place in the header and the binding is notified of these changes ( WindowName must be either Dependency or Resources must be implemented with INotifyPropertyChanged )

If Properties is a namespace (as is the case with the default properties generated by VS), you need to declare it somewhere using xmlns and use x:Static :

 <Window ... xmlns:prop="clr-namespace:App.Properties" Title="{Binding Source={x:Static prop:Resources.WindowName}}"> 

Another note. If you use Visual Studio managed resources, you need to make sure that the property access modifier is public , by default it is internal , which throws an exception, since the binding works only for public properties.

+10
source share

just delete this:

 ... ;assembly=ClassLibrary1" 
+1
source share

In fact, I have a Title in the static resource defined at the top of the application, and I bind the Title and everything I want to it

 <s:String x:Key="ApplicationName">My Application</s:String> 
0
source share

Have you tried to change the access modifier of the resource from internal to public?

I just had a problem with this now.

  /// <summary> /// Looks up a localized string similar to Has been impossible to load the configuration information. /// </summary> internal static string ERROR_NoConfigurationLoaded { get { return ResourceManager.GetString("ERROR_NoConfigurationLoaded", resourceCulture); } } 

to

  /// <summary> /// Looks up a localized string similar to Has been impossible to load the configuration information. /// </summary> public static string ERROR_NoConfigurationLoaded { get { return ResourceManager.GetString("ERROR_NoConfigurationLoaded", resourceCulture); } } 
0
source share

All Articles