Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 从CustomControl派生的类从何处获取资源?_Wpf - Fatal编程技术网

Wpf 从CustomControl派生的类从何处获取资源?

Wpf 从CustomControl派生的类从何处获取资源?,wpf,Wpf,对于CustomControl的Resources属性,其内容来自何处,如何在XAML中向其添加资源?Themes/Generic.xaml是最好的地方吗?我是否需要在控件的代码中进行某种资源合并 下面的代码可以动态加载资源,但我认为如果经常调用它,这可能会很慢 System.Uri resourceLocater = new System.Uri("/Themes/Generic.xaml", System.UriKind.Relative); ResourceDictionary d =

对于CustomControl的Resources属性,其内容来自何处,如何在XAML中向其添加资源?Themes/Generic.xaml是最好的地方吗?我是否需要在控件的代码中进行某种资源合并

下面的代码可以动态加载资源,但我认为如果经常调用它,这可能会很慢

 System.Uri resourceLocater = new System.Uri("/Themes/Generic.xaml", System.UriKind.Relative);
 ResourceDictionary d = (ResourceDictionary)Application.LoadComponent(resourceLocater);

您可以将资源放置在默认样式的
样式中。资源
,但是这些资源的访问应该限制在该样式中。如果它们仅在
模板中需要,您还可以使用
控制模板.Resources