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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -