c# - ItemsControl and ItemTemplateSelector in Windows 10 UWP app -


i did little wpf programming long time ago, returning xaml uwp, think should work , cannot figure out why. want use itemscontrol (because want list data, don't want selection) instead of listview control. here resources:

<page.resources>     <datatemplate x:key="sentmessagedatatemplate">         <textblock text="sent" />     </datatemplate>     <datatemplate x:key="receivedmessagedatatemplate">         <textblock text="recieved" />     </datatemplate>     <services:messagedatatemplateselector x:key="messagedatatemplateselector" receivedtemplate="{staticresource receivedmessagedatatemplate}" senttemplate="{staticresource sentmessagedatatemplate}"></services:messagedatatemplateselector> </page.resources> 

here itemscontrol:

<itemscontrol itemssource="{binding messages}" itemtemplateselector="{staticresource messagedatatemplateselector}" /> 

here datatemplateselector:

public class messagedatatemplateselector : datatemplateselector {     public datatemplate senttemplate     {         get;         set;     }      public datatemplate receivedtemplate     {         get;         set;     }      protected override datatemplate selecttemplatecore(object item)     {         var message = item messageviewmodel;         if (message == null)         {             return this.senttemplate;         }          return message.sent ? this.senttemplate : this.receivedtemplate;     } } 

instead of displaying either of templates displays viewmodel type name (so tostring).

however if switch itemscontrol listview, works fine.

any suggestions?

use override instead:

protected override datatemplate selecttemplatecore(object item, dependencyobject container) 

this 1 gets called, not 1 without 2nd parameter.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -