アクセス可能なリソース ディクショナリに 2 つのコントロール テンプレートを作成します。
彼らはこのように見えるはずです
<ControlTemplate x:key="debug_view">
<ViewBox>
<ContentPresenter Content={Binding} />
</ViewBox>
</ControlTemplate>
<ControlTemplate x:key="release_view">
<ContentPresenter Content={Binding} />
</ControlTemplate>
次に、これをメインビューで使用できます
<Window>
<ContentControl Template="{StaticResource debug_view}">
<UserControl /*Content*/ ...>
</ContentControl>
</Window>
StaticResource
次に、バインディングのルックアップ キーを「debug_view」から「release_view」に変更するだけで、前後に切り替えることができます
より動的にしたい場合は、さらにこれを行うことができます:
<Window>
<ContentControl Loaded="MainContentLoaded">
<UserControl /*Content*/ ...>
</ContentControl>
</Window>
次に、コードビハインドで
void MainContentLoaded(object sender, RoutedEventArgs e)
{
ContentControl cc = (ContentControl) sender;
#if DEBUG
sender.Template = (ControlTemplate) Resources["debug_view"];
#else
sender.Template = (ControlTemplate) Resources["release_view"];
#endif
}
このように、DEBUG シンボルが定義されているかどうかに応じて、異なるテンプレートが選択されます。