2017-12-15 21 views
0

Resource Dictionary을 사용하려하지만 스타일이 생성 된 것을 인식하지 못합니다. 리소스 사전을 해당 키로 어떻게 사용합니까?

<Window.Resources> 
    <RoutedUICommand x:Key="Add" Text="Add" /> 
    <RoutedUICommand x:Key="Cancel" Text="Cancel" /> 
    <RoutedUICommand x:Key="Exit" Text="Exit" /> 
    <ResourceDictionary x:Key="LightTheme" Source="/Themes/Light.xaml"/> 
</Window.Resources> 

내가 ResourceDictionary에 태그에서 x:Key을 삭제

, 그것은

을 "각 사전 관련 키가 있어야합니다"그러나 나는 내 스타일 중 하나를 사용하려고하면, 그것은 작동하지 않습니다라는 메시지가 표시 .

<Button x:Name="AddNew" Style="{StaticResource RoundCorner}"> 

답변

1

사전을 병합하십시오. 그렇게하려면 명시적인 ResourceDictionary 요소가 있어야합니다.

<Window.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/Themes/Light.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 

     <RoutedUICommand x:Key="Add" Text="Add" /> 
     <RoutedUICommand x:Key="Cancel" Text="Cancel" /> 
     <RoutedUICommand x:Key="Exit" Text="Exit" /> 

    </ResourceDictionary> 
</Window.Resources>