c# - Grid View or ListView Binding or Rendering of Collection of Collection -


a complete new bee in xaml , wpf shifted mvc 1 week back

requirement:

display customer name , corresponding brands

1 customer can have many brands

issue

unable display corresponding brands

reference

similar thread

code

public partial class mainwindow : window {      public mainwindow()     {         datacontext = new mydevicelist();         initializecomponent();     } }  public class mydevicelist {     entities ent = new entities();     public observablecollection<mycustomers> customers { get; set; }      public void getcustomersbrand()     {         var custall = (from c in ent.customers                     select new mycustomers{ name = c.name, brands = c.brands.tolist() }).tolist();          customers = new observablecollection<mycustomers>(custall);      }      public mydevicelist()     {         getcustomersbrand();     } }  //just dummy class public class brand {     public string name { get; set; }     public int customerid { get; set; } }   public class mycustomers {     public string name { get; set; }     public list<brand> brands { get; set; } }    

xaml

<window x:class="devicelistcreate.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:my="clr-namespace:devicelistcreate"     title="mainwindow" windowstate="maximized">  <window.resources>     <datatemplate x:key="grouptemplate" datatype="{x:type my:mycustomers}">         <itemscontrol itemssource="{binding brands}">             <itemscontrol.itemtemplate>                 <datatemplate>                     <textblock text="{binding name}"/>                 </datatemplate>             </itemscontrol.itemtemplate>         </itemscontrol>     </datatemplate> </window.resources> <grid>      <itemscontrol itemssource="{binding customers}" name="tstack" grid.column="0" margin="33,10,42,10">         <itemscontrol.itemspanel>             <itemspaneltemplate>                 <wrappanel/>             </itemspaneltemplate>         </itemscontrol.itemspanel>         <itemscontrol.itemtemplate>             <datatemplate>                 <grid>                     <textblock text="{binding name}"/>                                       </grid>             </datatemplate>         </itemscontrol.itemtemplate>     </itemscontrol> </grid> 

kindly guide direction should heading now

thanks in advance

when constructing ui this, have build part part. concentrating on each part individually makes whole task more manageable. try this:

<grid>     <itemscontrol itemssource="{binding customers}">         <itemscontrol.itemspanel>             <itemspaneltemplate>                 <wrappanel />             </itemspaneltemplate>         </itemscontrol.itemspanel>         <itemscontrol.itemtemplate>             <datatemplate>                 <border cornerradius="5" borderbrush="royalblue" borderthickness="1"                      padding="5" margin="5">                     <stackpanel orientation="horizontal">                         <textblock text="{binding name}" margin="5" />                         <itemscontrol itemssource="{binding brands}">                             <itemscontrol.itemspanel>                                 <itemspaneltemplate>                                     <stackpanel orientation="horizontal" />                                 </itemspaneltemplate>                             </itemscontrol.itemspanel>                             <itemscontrol.itemtemplate>                                 <datatemplate>                                     <checkbox content="{binding name}" margin="5" />                                 </datatemplate>                             </itemscontrol.itemtemplate>                         </itemscontrol>                     </stackpanel>                 </border>             </datatemplate>         </itemscontrol.itemtemplate>     </itemscontrol> </grid> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -