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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:04:18+00:00 2026-05-11T09:04:18+00:00

I have the following XAML: <Grid x:Name=root> <Grid.RowDefinitions> <RowDefinition Height=*/> <RowDefinition Height=Auto/> </Grid.RowDefinitions> <Grid.Resources>

  • 0

I have the following XAML:

<Grid x:Name='root'>    <Grid.RowDefinitions>     <RowDefinition Height='*'/>     <RowDefinition Height='Auto'/>  </Grid.RowDefinitions> <Grid.Resources>   <DataTemplate DataType='{x:Type ViewModels:TemplateViewModel}'>     <ContentControl Content='{Binding}' Grid.Row='0' x:Name='ct'>       <ContentControl.ContentTemplate>         <DataTemplate>           <TextBlock Text='Loaded' />          </DataTemplate>       </ContentControl.ContentTemplate>     </ContentControl>     <DataTemplate.Triggers>       <DataTrigger Binding='{Binding DataContext.State,             RelativeSource={RelativeSource AncestorType={x:Type Window}}}' Value='2'>         <Setter Property='ContentTemplate' TargetName='ct'>           <Setter.Value>             <DataTemplate>               <TextBlock Text='Loading, please wait'  Foreground='Red'/>             </DataTemplate>           </Setter.Value>         </Setter>       </DataTrigger>     </DataTemplate.Triggers>   </DataTemplate> </Grid.Resources> <ContentControl Content='{Binding MainContent}' /> 

That XAML is inside a Window element. I’m binding the Window to a ViewModel object with two properties, State and MainContent:

public class ViewModel : INotifyPropertyChanged {    public int State {...} // this can be only 1 or 2, for simplicity    public TemplateViewModel MainContent { ... }  } 

I raise the PropertyChanged event from the property setters accordingly.

Now, with a button I load a file from disk, parse it and create an object to assign to the MainContent property. Before parsing I set the State property to 2 (loading) and after assigning I reset the property to 1 (loaded).

The first time I parse the file, the trigger in the data template doesn’t work (notice the trigger is bound to the State property of the Data Context of the parent Window, that is, the ViewModel object). But the second time, it does!

Can somebody point where’s the error?

I’m afraid I cannot post the code here, but could share it if you have an answer and give me an email..

  • 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. 2026-05-11T09:04:18+00:00Added an answer on May 11, 2026 at 9:04 am

    Your DataTemplate is applied to type TemplateViewModel instead of ViewModel. Ergo, it won’t apply to anything until the MainContent property is set.

    • 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: <Grid x:Name=ContentPanelDaily Grid.Row=1 <Grid.RowDefinitions> <RowDefinition Height=40 /> </Grid.RowDefinitions> <Grid.ColumnDefinitions>
I have the following XAML: <UserControl.Resources> <DataTemplate x:Key=ExpanderTemplate> <Grid> <Rectangle Stroke=Black StrokeThickness=1 Width=10 Height=10
I have the following XAML: <UserControl.Resources> <local:MainPageViewModel x:Key=ViewModel /> </UserControl.Resources> <Grid x:Name=LayoutRoot DataContext={Binding Source={StaticResource
I have the following XAML: <Grid x:Name=LayoutRoot Background=White DataContext={Binding Source={StaticResource MyDataKey}}> <TextBox Name=_myId Text={Binding
I currently have the following XAML for my Grid control: <dxg:GridControl x:Name=DXGrid> <dxg:GridControl.Columns> <dxg:Column
I have the following xaml: <Border BorderBrush=Black BorderThickness=1.5 CornerRadius=5> <Grid ShowGridLines=True> <Grid.ColumnDefinitions> <ColumnDefinition Width=Auto/>
Is this a known issue? I have the following XAML: <Grid x:Name=LayoutRoot> <Popup> <Slider
I have the following XAML: <ListBox HorizontalAlignment=Left Margin=0,6,0,10 Name=listBox1 Width=468 ItemsSource={Binding} Grid.ColumnSpan=1> <ItemsControl.ItemTemplate> <DataTemplate>
I have the following XAML on my page: <Grid x:Name=LayoutRoot> <Viewbox Stretch=Uniform> <Image x:Name=myImage
I'm developing a Windows Phone app. I have the following XAML code: <Grid x:Name=ContentPanel

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.