मेरे पास एक त्रुटि संवाद है (नीचे सरलीकृत दिखाया गया है)।चेकबॉक्स का उपयोग करके एक WPF नियंत्रण के टेम्पलेट को गतिशील रूप से कैसे बदलें?
मैं एक ContentControl में रिपोर्ट वस्तु प्रदर्शित जो मैं एक खाकाsimpleErrorTemplate परिभाषित किया है करने के लिए।
खिड़की है कि मैं/से detailedErrorTemplate करने के लिए टेम्पलेट बदलने के लिए उपयोग करना चाहते हैं पर एक चेक बॉक्स नहीं है। इस लक्ष्य को हासिल करने का सबसे अच्छा तरीका क्या है?
<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: क्या आप टेम्पलेट को कंटेंट कंट्रोल से स्टाइल में सेटर में ले जाते हैं? –
@chillitom: मेरा जवाब अपडेट किया गया। आपको बस कॉपी करने/पेस्ट करने में सक्षम होना चाहिए और यह देखने के लिए कि आप क्या खो रहे हैं, –