积极答复者
怎么把一个wpf应用程序项目生成为一个组件

问题
答案
-
是因为类库项目里面不能有Application 实例,所以你把App.xaml删掉就好了。
有任何疑问,欢迎来MSDN WPF论坛!
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2011年5月3日 10:29
- 已标记为答案 Jie BaoModerator 2011年5月11日 11:39
-
是的,其实App.xaml本身是个ResourceDictonary,所以正确的生成组件并且包含你的定义的Resource方法是:
- 新建一个Wpf Application, 删除 App.xaml 更改项目输出类型为库
- 打开解决方案中的 Properties目录下的 AssemblyInfo.cs文件
- 修改增加以下这个标签:
[assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )]
- 然后你就需要在项目增加一个名为 Themes 的目录,在目录里面添加一个名为 Generic.xaml 的ResourceDictionary
- 这样,你就可以把在App.xaml中定义的资源全部放在Generic.xaml中了,系统根据程序集的设置会默认从这个资源目录中去寻找资源
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2011年5月5日 16:41
- 已标记为答案 wizardhy 2011年5月6日 3:05
- 取消答案标记 wizardhy 2011年5月8日 13:06
- 已标记为答案 Jie BaoModerator 2011年5月11日 11:39
全部回复
-
是因为类库项目里面不能有Application 实例,所以你把App.xaml删掉就好了。
有任何疑问,欢迎来MSDN WPF论坛!
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2011年5月3日 10:29
- 已标记为答案 Jie BaoModerator 2011年5月11日 11:39
-
是的,其实App.xaml本身是个ResourceDictonary,所以正确的生成组件并且包含你的定义的Resource方法是:
- 新建一个Wpf Application, 删除 App.xaml 更改项目输出类型为库
- 打开解决方案中的 Properties目录下的 AssemblyInfo.cs文件
- 修改增加以下这个标签:
[assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )]
- 然后你就需要在项目增加一个名为 Themes 的目录,在目录里面添加一个名为 Generic.xaml 的ResourceDictionary
- 这样,你就可以把在App.xaml中定义的资源全部放在Generic.xaml中了,系统根据程序集的设置会默认从这个资源目录中去寻找资源
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Jie BaoModerator 2011年5月5日 16:41
- 已标记为答案 wizardhy 2011年5月6日 3:05
- 取消答案标记 wizardhy 2011年5月8日 13:06
- 已标记为答案 Jie BaoModerator 2011年5月11日 11:39
-
静态引用必须是可以直接找到的,这个资源是要直接被Merge合并到当前项目的。所以你的问题可能在于
1:你没有把资源合并,参考资源合并 http://msdn.microsoft.com/zh-cn/library/aa350178.aspx
2:你需要的是 动态引用,而不是静态:DynamicResource
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.