Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:53:41+00:00 2026-06-11T19:53:41+00:00

I have the following controls/views: myControl containing a ContentControl and two ControlTemplates in the

  • 0

I have the following controls/views:

  • myControl containing a ContentControl and two ControlTemplates in the UserControl.Resources
  • Main application (Window) with an instance of myControl and a ToggleButton

I want to switch between my two ControlTemplates via the ToggleButton in the main application.

This should be very easy … but I cannot find a proper way :S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:53:42+00:00Added an answer on June 11, 2026 at 7:53 pm

    A simpler solution is to bind to the content property of the content control and define datatemplates for each type of content.

    <Window.Resources>
    
        <DataTemplate DataType="{x:Type local:MyType1}">
            <Border Background="Red" />
        </DataTemplate>
    
        <DataTemplate DataType="{x:Type local:MyType2}">
            <Border Background="Green" />
        </DataTemplate>
    
    </Window.Resources>
    

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="24" />
        </Grid.RowDefinitions>
        <ContentControl Content="{Binding MyContent}" />
        <ToggleButton Grid.Row="1"
                      Content="Toggle"
                      IsChecked="{Binding IsChecked}" />
    </Grid>
    

    //DataContext
    public bool IsChecked
    {
      get { return isChecked_; }
    
      set 
      { 
        isChecked_ = value;
        NotifyPropertyChanged_("IsChecked");
    
        if (value)
          MyContent = new MyType1();
        else
          MyContent = new MyType2();
      }
    }
    
    public object MyContent
    {
        get { return myContent_; }
        set 
        {
           myContent = value;
           NotifyPropertyChange_("MyContent");
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main window which hosts two views (user controls). One is UserControl1
I have the following controls: <UserControl > <!--<ScrollViewer >--> <Viewbox > <Canvas/> </Viewbox> <!--</ScrollViewer>-->
I have the following XAML: <UserControl x:Class=EMS.Controls.Dictionary.TOCControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:vm=clr-namespace:EMS.Controls.Dictionary.Models xmlns:diagnostics=clr-namespace:System.Diagnostics;assembly=WindowsBase x:Name=root > <TreeView
I have following user control: <UserControl.Resources> <Style TargetType=HeaderedItemsControl> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=HeaderedItemsControl> <Grid>
I have the following two controls in my code gridview (for data display) sqldatasource
I have the following defined at the top of my XAML: <controls:ChildWindow x:Class=MyProject.SilverlightUI.Views.CharacterGenerator xmlns:my=clr-namespace:MyProject.SilverlightUI.ViewModels
I have the following code that controls the presentation of an interdependent group. The
I have the following code: foreach (var control in this.Controls) { } I want
I have the following code: <video width=640 height=360 controls id=video-player poster=/movies/poster.png> <source src=/movies/640x360.m4v type='video/mp4;
I have the following HTML with a value of 1-99 visible: <ul class=controls-buttons question-controls>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.