如何使用Themes \Generic.xaml应用自定义控件的默认模板? [英] How is the default template of a custom control applied with out using Themes\Generic.xaml ?

查看:89
本文介绍了如何使用Themes \Generic.xaml应用自定义控件的默认模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



我使用默认模板创建了自定义内容控件。

虽然该模板不在Themes \Generic.xaml位置,但应该如此。相反,我将它放在一个具有不同名称的单独资源字典中。

它与App.xaml资源字典中的其他资源字典一起合并。



运行代码没有产生任何错误,控件是可见。我在其他机器上测试了应用程序并且代码运行得很好,我想指出这些机器是开发机器。



在客户机上测试应用程序(非开发)然后发现了一些奇怪的行为。自定义控件不可见;它只能在1台3台客户端机器上看到。



我能够通过将模板放入Themes \Generic.xaml来解决问题。



我的问题是如何在不必将模板放入Themes\Generic.xaml的情况下工作?我在Google上搜索过,但我可以找到任何明确的解释。



谢谢

Hello

I created a custom content control with its default template.
The template though is not located in the location "Themes\Generic.xaml" as it is supposed to be. Instead I placed it in a separate resource dictionary with a different name.
It is merged along with other resource dictionaries in the App.xaml resource dictionary.

Running the code yielded no errors and the control is visible. I tested the application on other machines and the code ran just fine , I would like to point out that these machines are development machines.

Testing the application on the client machines (non development) then revealed some strange behaviour. The custom control was not visible; it would only be visible on 1 out 3 client machines.

I was able to fix the problem by putting the template in "Themes\Generic.xaml".

My question is how was it able to work without having to put the template in "Themes\Generic.xaml" ? I have searched on Google but I could find any clear cut explaination .

Thank you

推荐答案

if你提供DefaultStyleKey = typeof(ControlEx)

只有它会在主题/ Generic.xaml中搜索模板

否则它将采用基类模板。
if you provide DefaultStyleKey=typeof(ControlEx)
only that time it will search for template in Themes/Generic.xaml
otherwise it will take base class template .


这篇关于如何使用Themes \Generic.xaml应用自定义控件的默认模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆