title: XAML TemplateSelector seems kind of delayed
body: <p>Currently i'm facing a really weird problem. My template selector seems to be some kind of delayed.</p>
  <p>Really rough description of my current situation, i'm devolping a simple UWP application with a nested listview to display some items grouped by fixed properties. These Items should be editable by switching the View from &quot;ViewMode&quot; to &quot;EditMode&quot;. By enabling the &quot;EditView&quot; the First ListView isn't updated to the EditView template...?! But Why? I Made a complete Demo example which consists of the View User Control, the Main Page and a Demo Model classes as follows (the complete demo on github: <a href="https://github.com/tzdlr/SODemo" rel="nofollow noreferrer">https://github.com/tzdlr/SODemo</a>):</p>
  <p>UWP Page:</p>
  <pre><code>&lt;Page
      x:Class=&quot;UWPTest.MainPage&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:local=&quot;using:UWPTest&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      mc:Ignorable=&quot;d&quot;
      Background=&quot;{ThemeResource ApplicationPageBackgroundThemeBrush}&quot;&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height=&quot;auto&quot;&gt;&lt;/RowDefinition&gt;
              &lt;RowDefinition Height=&quot;*&quot;&gt;&lt;/RowDefinition&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;CommandBar Grid.Row=&quot;0&quot;&gt;
              &lt;AppBarToggleButton Icon=&quot;Edit&quot; Label=&quot;Bearbeitungs-Ansicht&quot; IsChecked=&quot;{x:Bind EditMode, Mode=TwoWay}&quot; /&gt;
          &lt;/CommandBar&gt;
          &lt;local:ListViewControl Grid.Row=&quot;1&quot; MyListCollection=&quot;{x:Bind MyList}&quot;&gt;&lt;/local:ListViewControl&gt;
      &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>
  <p>UWP UserControl</p>
  <pre><code>&lt;UserControl
      x:Class=&quot;UWPTest.ListViewControl&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:local=&quot;using:UWPTest&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      mc:Ignorable=&quot;d&quot;
      d:DesignHeight=&quot;300&quot;
      d:DesignWidth=&quot;400&quot;&gt;
      &lt;UserControl.Resources&gt;
          &lt;DataTemplate x:Key=&quot;DTView&quot; x:DataType=&quot;local:Model&quot;&gt;
              &lt;Grid&gt;
                  &lt;TextBlock Text=&quot;{x:Bind Text}&quot;&gt;&lt;/TextBlock&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
  
          &lt;DataTemplate x:Key=&quot;DTEdit&quot; x:DataType=&quot;local:Model&quot;&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width=&quot;*&quot;&gt;&lt;/ColumnDefinition&gt;
                      &lt;ColumnDefinition Width=&quot;auto&quot;&gt;&lt;/ColumnDefinition&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;TextBox Grid.Column=&quot;0&quot; Text=&quot;{x:Bind Text,Mode=TwoWay}&quot;&gt;&lt;/TextBox&gt;
                  &lt;Button Grid.Column=&quot;1&quot; Content=&quot;Delete&quot;&gt;&lt;/Button&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
  
          &lt;local:ModelSelector x:Key=&quot;tplSelector&quot;
              ViewTemplate=&quot;{StaticResource DTView}&quot;
              EditTemplate=&quot;{StaticResource DTEdit}&quot; /&gt;
  
  
      &lt;/UserControl.Resources&gt;
  
      &lt;ListView x:Name=&quot;list&quot; ItemsSource=&quot;{x:Bind MyListCollection, Mode=TwoWay}&quot;&gt;
          &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate x:DataType=&quot;local:ListModel&quot;&gt;
                  &lt;ListView ItemsSource=&quot;{x:Bind ModelList,Mode=TwoWay}&quot; ItemTemplateSelector=&quot;{StaticResource tplSelector}&quot;&gt;&lt;/ListView&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
  
  &lt;/UserControl&gt;
  </code></pre>
  <p>My models and other classes:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Windows.UI.Xaml;
  using Windows.UI.Xaml.Controls;
  
  namespace UWPTest
  {
      public class Model
      {
          public string Text;
  
          public Model(string t) { Text = t; }
      }
  
      public class ListModel
      {
          public List&lt;Model&gt; ModelList = new List&lt;Model&gt;();
      }
  
      public class ModelSelector : DataTemplateSelector
      {
          public DataTemplate ViewTemplate { get; set; }
          public DataTemplate EditTemplate { get; set; }
  
          protected override DataTemplate SelectTemplateCore(object item)
          {
              return StaticHelper.EditView ? EditTemplate : ViewTemplate;
          }
  
          protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
          {
              return StaticHelper.EditView ? EditTemplate : ViewTemplate;
          }
      }
      static class StaticHelper
      {
          public static bool EditView { get; set; } = false;
      }
  
      public class DataService
      {
          private List&lt;ListModel&gt; _cache = new List&lt;ListModel&gt;();
  
          public void LoadData()
          {
              _cache.Clear();
              for (var i = 0; i &lt; 5; i++)
              {
                  ListModel nl = new ListModel();
                  for (var k = 0; k &lt; 10; k++)
                  {
                      nl.ModelList.Add(new Model(i + &quot;-&quot; + k));
                  }
                  _cache.Add(nl);
              }
          }
  
          public List&lt;ListModel&gt; getCachedEntries()
          {
              return _cache;
          }
      }
  }
  
  </code></pre>
  <p>And here is the result, window behind in &quot;ViewMode&quot;, window in Front: &quot;EditView&quot;:</p>
  <p><a href="https://i.stack.imgur.com/2jqp9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2jqp9.png" alt="enter image description here" /></a></p>