wpf类全局?

时间:2012-09-09 00:57:09

标签: c# wpf xaml

IM本质上不是C#程序员,但我可以根据需要使用它。我试图学习WPF,我的问题是,我可以在App.xaml中声明我的类并从我的所有单独控件中访问它吗?我主要对此感兴趣,因为我想要有一个LogWriter并让所有人都与之交谈。

<!-- 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 个答案:

答案 0 :(得分:1)

设置x:Key,使用StaticResource进行参考。 Application.Resources可在应用程序的任何位置访问。

相关问题