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
Wpf-资源查找_Wpf - Fatal编程技术网

Wpf-资源查找

Wpf-资源查找,wpf,Wpf,我想知道控件是查看它们自己的资源还是它们的父资源 让我们这样说: <StackPanel> <Button someProp={StaticResource test1}> <Button.Resources> <local:something x:Key="test1"/> </Button.Resources> </Button> <StackPanel> Button是在自己的资源字

我想知道控件是查看它们自己的资源还是它们的父资源

让我们这样说:

<StackPanel>
 <Button someProp={StaticResource test1}>
  <Button.Resources>
   <local:something x:Key="test1"/>
  </Button.Resources>
 </Button>
<StackPanel>

Button是在自己的资源字典中查找test1,还是要求其父级(StackPanel)查找它


如果这个问题是重复的,我很抱歉。

基本上,框架将首先在最本地的
资源
集合中查找
资源,在这种情况下,
按钮
。如果没有找到任何内容,它将继续查找控制层次结构,在本例中,将查找到
StackPanel.Resources
部分

在此之后,它将查看
UserControl.Resources
(如果适用),然后是
窗口.Resources
,最后是
App.Resources
集合

您可以在MSDN的页面上找到更多信息