app.xaml에 사용자 정의 명명 된 스타일을 추가했습니다.리소스 사전의 DataTemplates는 app.xaml 스타일을 상속하지 않습니까?
외부 리소스 사전 (app.xaml의 병합 된 사전에 첨부)을 만들었으며 rcource 사전에서 위의 스타일 중 하나를 사용하려고하면 스타일이 없다고 말합니다.
또한 기본 스타일 (전체 애플리케이션에 적용되는 이름없는 스타일)은 템플릿 요소에 적용되지 않습니다.
참고 : 템플릿의 빌드 작업은 '페이지'입니다.
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShutdownMode="OnExplicitShutdown">
<Application.Resources>
<ResourceDictionary>
<Style
x:Key="StackPanelStyle"
TargetType="StackPanel"
BasedOn="{StaticResource {x:Type StackPanel}}">
<Setter Property="Margin" Value="5"/>
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="Height" Value="40"/>
</Style>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Templates/DataTemplate1.xaml"/>
<ResourceDictionary Source="/Templates/DataTemplate2.xaml"/>
<ResourceDictionary Source="/Templates/DataTemplate3.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
이 데이터 템플릿의 예 :
<DataTemplate DataType="{x:Type Entity}" x:Key="NameDataTemplate">
<Expander>
<StackPanel>
<--The following line produces: StackPanelStyle was not found.-->
<StackPanel Style="{StaticResource StackPanelStyle}">
<Label Content="Name:"/>
<TextBox Text="{Binding Name}"/>
</StackPanel>
</StackPanel>
</Expander>
</DataTemplate>
모든 아이디어를 여기
내 코드를 작성하는 방법의 예입니다? 사전을 다른 방식으로 병합해야합니까?
호기심에서 벗어나서, 어떤 리소스 사전 파일에'NameDataTemplate'이 저장되어 있습니까? – devuxer
그냥 예제 일 뿐이므로, DataTemplates가 병합되기 전에 스타일이 app.xaml에 표시된다는 것을 강조했습니다. – Shimmy