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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:53:45+00:00 2026-05-28T01:53:45+00:00

I have ContentPresenter with DataTemplateSelector: … public override DataTemplate SelectTemplate(object item, DependencyObject container) {

  • 0

I have ContentPresenter with DataTemplateSelector:

    ...

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        var model = item as ItemControlViewModel;

        if (model.CurrentStatus == PrerequisitesStatus.Required)
        {
            return RequiredTemplate;
        }

        if (model.CurrentStatus == PrerequisitesStatus.Completed)
        {
            return FinishedTemplate;
        }

        ...

        return InProgressTemplate;
    }

When CurrentStatus is changed, OnPropertyChanged is called.

I need somehow to trigger this DataTemplateSelector when the property is changed and change ContentPresenter DataTemplate. Any suggestions?

Threre are similar questions:
1
2, but I don’t want to use any DataTriggers, because of too much states.

Tried to play with DataTriggers

    <ContentPresenter
        Grid.Column="1"
        Height="16"
        Width="16"
        Margin="3">
        <ContentPresenter.Triggers>
            <DataTrigger Binding="{Binding Path=CurrentStatus}" Value="0">
                <Setter Property="ContentPresenter.ContentTemplate" Value="{StaticResource ResourceKey=_requiredStatusTemplate}" />
            </DataTrigger>
        </ContentPresenter.Triggers>
    </ContentPresenter>

But got an error:
Triggers collection members must be of type EventTrigger 🙁

  • 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-05-28T01:53:46+00:00Added an answer on May 28, 2026 at 1:53 am

    As you requested an example with datatriggers in the comments, here you are:

    A FrameworkElement can only have EventTriggers, therefore you get the error Message Triggers collection members must be of type EventTrigger

    And also don’t use a ContentPresenter directly, it is meant to be used inside a ControlTemplate. Better use a ContentControl when you want to have dynamic content.
    See What's the difference between ContentControl and ContentPresenter?

    And finally here’s a suggestion to your DataTrigger issue. I have put it inside a style for reusability ….

    XAML :

    <Window x:Class="WpfApplication88.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
      <Window.Resources>
    
        <DataTemplate x:Key="requiredTemplate">
          <TextBlock Text="requiredTemplate"></TextBlock>
          <!--your stuff here-->
        </DataTemplate>
    
        <DataTemplate x:Key="completedTemplate">
          <TextBlock Text="CompletedTemplate"></TextBlock>
          <!--your stuff here-->
        </DataTemplate>
    
        <Style x:Key="selectableContentStyle" TargetType="{x:Type ContentControl}">
          <Style.Triggers>
            <DataTrigger Binding="{Binding Path=CurrentStatus}" Value="Required">
              <Setter Property="ContentTemplate" Value="{StaticResource requiredTemplate}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=CurrentStatus}" Value="Completed">
              <Setter Property="ContentTemplate" Value="{StaticResource completedTemplate}" />
            </DataTrigger>
            <!--  your other Status' here -->
          </Style.Triggers>
        </Style>
    
      </Window.Resources>
    
      <Grid>
        <ContentControl Width="100" Height="100" Style="{StaticResource selectableContentStyle}"/>
      </Grid>
    
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XAML: <GridView x:Key=myGridView> <GridViewColumn CellTemplate={StaticResource myTemplate}/> </GridView> <DataTemplate x:Key=myTemplate> <ContentPresenter
I have tried this: <DataTemplate x:Key=RowItemTemplate> <ItemsControl ItemTemplate={StaticResource ResourceKey=BorderItemTemplate} ItemsSource=ContentPresenter.Content> </ItemsControl> </DataTemplate> and it
Ok I have a contentpresenter inside a grid cell: <Grid> <Grid.RowDefinitions> <RowDefinition Height=Auto></RowDefinition> <RowDefinition></RowDefinition>
I have the following AutoCompleteBox defined inside DataTemplate: <Window.Resources> <DataTemplate x:key=PaneTitleTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition
I have this code. For some reason I can't get the contentpresenter to stretch
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a custom styled ListBoxItem with a Border surrounding a ContentPresenter . (Code
I have a datatemplate for my listbox: <DataTemplate x:Key=CheckBoxTextBoxItemTemplate> <StackPanel Orientation=Horizontal> <CheckBox Focusable=False IsChecked={Binding
I have an <ItemsControl> with a custom <DataTemplate> (and also a custom <ItemsPanelTemplate> that
I have a DataTemplate : <DataTemplate x:Key=myTemplate> ... </DataTemplate> I want to use it

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.