标题并没有真正意义......对此感到抱歉。我会尽力解释我的问题。我有一个更大的项目,我正在尝试实现一个包含一些自定义控件的新 WPF 窗口。再深入一点,这个窗口应该看起来像一个计算器。这个计算器有许多键按钮,它们是从 Controls 继承的“自定义控件”,它们的样式在 Generic.xaml 中定义。当我尝试调试它时,自定义控件(按键)不会出现在计算器窗口中。我认为这是由于 Generic.xaml 文件有问题。有人可以给我一个提示吗???提前感谢保罗
2 回答
我在网上搜索了很多,最后我得到了这个讨论wpf-resource-not-loading-from-generic的答案的解决方案。线索是将这些代码行添加到 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)
)]
也许这对将来的某人有用...... :-)
问候,保罗
A couple of suggestions:
download Snoop (it's free), it examines your Visual tree at run time and helps to see if controls are there, if the style making them invisible, etc.
remove the styles, run your project - do controls appear? then it's your styles!
do you have nameless/key-less styles that target buttons, other simple/out-of-the-box control? Then remove them too, if they are the ones affecting your controls, then consider changing them, or applying styles to your controls so they stop inheriting from those defaults.