目前我正在做这样:数据窗口标题绑定到应用程序资源
public MainWindow()
{
InitializeComponent();
Title = Properties.Resources.WindowName;
}
如何通过WPF结合做?
编辑:它仍然无法在XAML中工作。
环境:VS2010,.NET 4.0,Windows 7的
繁殖步骤:
的代码创建类库ClassLibrary1的:
namespace ClassLibrary1
{
static public class Class1
{
static public string Something
{
get { return "something"; }
}
}
}
在VS2010 .NET 4.0中创建WPF Windows应用程序。
编辑主窗口的XAML:
<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}">
...
编译错误信息:
MainWindow.xaml(7,130):错误MC3029: 'ClassLibrary1的:1类' 成员无效,因为它没有合格的类型名称。
我还发现此主题My.Resources in WPF XAML?。 而且它似乎都应该工作,但它不。
Microsoft不对此错误消息给出说明。只有帮助论坛http://social.msdn.microsoft.com/Forums/en/wpf/thread/4fe7d58d-785f-434c-bef3-31bd9e400691中的另一个主题,这也没有帮助。
在这种情况下的路径应该是'X里面:Static'的属性是静态的,即'{绑定源= {x:Static ClassLibrary1:Class1.Something}}',请参阅[参考页](http://msdn.microsoft.com/zh-cn/library/ms742135.aspx)上的语法。我也更新了我的答案,这是错误的... – 2011-09-24 15:48:25