2012-09-09 89 views
0

即时通讯不是C#程序员,但我确实需要它。我试图学习WPF和我的问题是,我可以在App.xaml中声明我的类,并从我的所有单独的控件访问它?我主要对此感兴趣,因为我不想让一个LogWriter让所有人都跟它交谈。wpf类全球?

<!-- App.xaml --> 
<Application x:Class="MyAPP.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:src="clr-namespace:LogWriter" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
<src:LogWriter x:Name="LogWriter"/> 
</Application.Resources> 
</Application> 
+1

H.Bs答案就够了。只是为了澄清:资源是字典。因此它们中的资源没有被命名,但给了一个密钥。带有动画,触发器和ElementName绑定的模板中通常需要名称。在MSDN中是关于资源查找的好文章。阅读关于StaticResource应该是一个好的开始。 – dowhilefor

回答