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 8648781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:23:39+00:00 2026-06-12T13:23:39+00:00

I have a ContentControl that I need to set it’s ContentTemplate dynamically. so I

  • 0

I have a ContentControl that I need to set it’s ContentTemplate dynamically.

so I decided to write 2 DataTemplates, and then style my ContentControl such that a trigger fires and set the proper template (dt1/dt2) when a Boolean dependency property in my view-model changes (true/false).

But the problem is if the Boolean property is primarily set to true, the data template will always be dt1 and changing the property to false wont change the template to dt2.

since the data triggers are bound to the Boolean dependency property, shouldn’t changing the property result in firing the triggers?

notes:

  • There is a button in MyView which changes BooleanDependencyProp on it’s
    click event.
  • MyViewModel inherits from an interface that
    implements INotifyPropertyChanged.

Xaml:

<UserControl x:Class="Views.MyView">
...

<StackPanel>
    <ContentControl Content="{Binding RelativeSource={RelativeSource AncestorType=MyView}, Path=MyViewModel}">
        <ContentControl.Style>
            <Style TargetType="{x:Type ContentControl}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding BooleanDependencyProp}" Value="true">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <dt1 ... />
                                                    </Setter.Value>
                                                </Setter>
                    <DataTrigger Binding="{Binding BooleanDependencyProp}" Value="false">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <dt2 ... />
                                                    </Setter.Value>
                                                </Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
</StackPanel>
  • 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-12T13:23:40+00:00Added an answer on June 12, 2026 at 1:23 pm

    This is a known shortcoming of the WPF framework, if you want to apply different data templates, consider either using the visual state manager to change the presentation, or swap out the content data template for a user control that changes based on the triggers instead, you’ll get more mileage.

    There’s a lot more I could say, but it would involve knowing your scenario and the differences in these DataTemplates, why you are disambiguating, etc. Also, MVVM all around? or straight ahead Code+Markup style with a few view models?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect that the ContentControl which have a property of ContentTemplate is either a
In my Silverlight 4 application, I have a ContentControl with its ContentTemplate property bound
In my application, I have a lot of RichTextBoxes that are created dynamically in
f I have a ContentControl... and its Content is set to a custom Image...
I have a UserControl that contains two ContentControls that need to have different UserControl
I have a mvvm(model view viewmodel) silverlight application that has several views that need
I have a window that has a StackPanel, and the StackPanel has a ContentControl,
I have a usercontrol that acts as a container for a ContentControl. The user
So I have a StackPanel that I am using as a ContentControl. I have
I have custom ContentControl called TabItem public class TabItem : ContentControl I have set

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.