내 사용자 정의 컨트롤의 스타일을 설정하려고합니다. UserControl은 프로젝트 "Controls"에 있고 테마는 프로젝트 "MainProject"에 있습니다.사용자 컨트롤의 스타일 설정
<UserControl x:Class="Controls.OutputPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="OutputControl">
<!-- Style="{DynamicResource UserControlStyle}"> - I cant set the style here because the Resource Dictionary hasn't been defined yet -->
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MainProject;component/Themes/MyTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<!-- Now that the Resource Dictionary has been defined I need to set the style -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="textbox"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Text="{Binding ElementName=OutputControl, Path=TextProperty}"
IsReadOnly="True"
Style="{DynamicResource OutputTextBoxStyle}"/>
</Grid>
</UserControl>
할 수있는 가장 좋은 앱 리소스에 리소스 사전에로드하는 것입니다. 이렇게하면 응용 프로그램을 시작할 때 사용할 수 있습니다. – jjrdk
프로젝트는 UserControlLibrary이므로이 작업을 수행 할 App.xaml 파일이 없습니다. –