오류 대화 상자가 있습니다 (아래 그림 참조). 확인란을 사용하여 동적으로 WPF 컨트롤의 템플릿을 변경하는 방법은 무엇입니까?
나는 어떤 나는 템플릿 simpleErrorTemplate을 정의하는 ContentControl을에서 보고서 객체를 표시합니다.내가/에서 detailedErrorTemplate에 템플릿을 변경하는 데 사용할하고자하는 창에 CheckBox의 있습니다. 이것을 달성하는 가장 좋은 방법은 무엇입니까?
<Window x:Class="Core.ErrorDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.Resources>
<ControlTemplate x:Key="simpleErrorTemplate">
<TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Message}" />
</ControlTemplate>
<ControlTemplate x:Key="detailedErrorTemplate">
<TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Message}" />
<TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Details}" />
<TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding StackTrace}" />
</ControlTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" Template="{StaticResource simpleErrorTemplate}" DataContext="{Binding Report}"/>
<CheckBox Margin="10,0,0,0" Grid.Row="1" x:Name="ChkShowDetails">Show Details</CheckBox>
</Grid>
</Window>
덕분에이 링크를 참조, 나는 이것이 비록 시도 준과 작동하지 않는 것, 스타일이 – chillitom
@chillitom 업데이트되지 않습니다나요 템플릿을 ContentControl에서 스타일의 Setter로 이동합니까? –
@chillitom : 내 대답이 업데이트되었습니다. 그 코드를 복사하여 붙여 넣기하고 코드와 비교하여 누락 된 부분을 확인하십시오 –