无法通过同一资源字典中定义的ComponentResourceKey定位资源 [英] Unable to locate resource by ComponentResourceKey defined in the same resource dictionary

查看:123
本文介绍了无法通过同一资源字典中定义的ComponentResourceKey定位资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

假设我正在编写WPF自定义控件.我在单独的程序集中得到它.另外,我在单独的ResourceDictionary中定义了所有资源.作为键,我使用ComponentResourceKey对象.

Suppose I'm writing a WPF custom control. I got it in a separate assembly. Also I defined all resources in a separate ResourceDictionary. As a keys I use ComponentResourceKey objects.

ResourceDictionary:

ResourceDictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     xmlns:local="clr-namespace:CustomControlLibrary">



 <HierarchicalDataTemplate x:Key="{x:Static local:CustomControlResources.AreaNodeDataTemplateKey}" 

        DataType="{x:Type local:AreaNode}" ItemsSource="{Binding Path=Nodes}">

 

  <StackPanel Orientation="Horizontal" Margin="1">

   <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" VerticalAlignment="Center"/>

  </StackPanel>

 </HierarchicalDataTemplate>



 <HierarchicalDataTemplate x:Key="{x:Static local:CustomControlResources.LeafNodeDataTemplateKey}" 

        DataType="{x:Type local:LeafNode}">

  <StackPanel x:Name="panel" Orientation="Horizontal" Margin="1">

   <TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center"/>

  </StackPanel>

 </HierarchicalDataTemplate>



 <local:NodeDataTemplateSelector x:Key="{x:Static local:CustomControlResources.DataTemplateSelectorKey}"

         AreaDataTemplate="{StaticResource {x:Static local:CustomControlResources.AreaNodeDataTemplateKey}}"

         LeafDataTemplate="{StaticResource {x:Static local:CustomControlResources.LeafNodeDataTemplateKey}}"/>



 <Style TargetType="{x:Type local:CustomControl}">

  <Setter Property="HorizontalAlignment" Value="Stretch"/>

  <Setter Property="VerticalAlignment" Value="Stretch"/>

  <Setter Property="Template">

   <Setter.Value>

    <ControlTemplate TargetType="{x:Type local:CustomControl}">

     <Grid>

      <TreeView ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsSource}"

         ItemTemplateSelector="{StaticResource {x:Static local:CustomControlResources.DataTemplateSelectorKey}}"/>

     </Grid>

    </ControlTemplate>

   </Setter.Value>

  </Setter>

 </Style>



</ResourceDictionary>

推荐答案

CS文件位于哪个命名空间?资源字典标记是否引用了该名称空间?
What namespace is the CS file in?  Does the resource dictionary markup have reference to that namespace?


这篇关于无法通过同一资源字典中定义的ComponentResourceKey定位资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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