c# - UC with items defined into xaml? -


i'm trying create user control accepts collection of items directly xaml (without binding datacontext), combobox:

    <combobox>         <comboboxitem content="test"/>         <comboboxitem content="test2"/>         <comboboxitem content="test3"/>     </combobox> 

also, in class of control, want receive list of items inputed inside uc on xaml. possible?

** edit **

i need receive more 1 list, say, 3 lists:

    <mycontrol>         <mycontrol.firstcollection>             <mycontrolitem content="test"/>             <mycontrolitem content="test2"/>             <mycontrolitem content="test3"/>         </mycontrol.firstcollection>         <mycontrol.secondcollection>             <mycontrolitem content="test4"/>             <mycontrolitem content="test5"/>             <mycontrolitem content="test6"/>         </mycontrol.secondcollection>         <mycontrol.lastcollection>             <mycontrolitem content="test7"/>             <mycontrolitem content="test8"/>             <mycontrolitem content="test9"/>         </mycontrol.lastcollection>     </mycontrol> 

how can receive 3 lists?

i don't want use container make items visible, want children controls , put list or collection

if not visual elements can create lists on user control

example: (using frameworkelement lists)

usercontrol:

public partial class usercontrol1 : usercontrol {     public usercontrol1()     {         initializecomponent();     }      public observablecollection<frameworkelement> firstcollection     {         { return (observablecollection<frameworkelement>)getvalue(firstcollectionproperty); }         set { setvalue(firstcollectionproperty, value); }     }      // using dependencyproperty backing store firstcollection.  enables animation, styling, binding, etc...     public static readonly dependencyproperty firstcollectionproperty =         dependencyproperty.register("firstcollection", typeof(observablecollection<frameworkelement>), typeof(usercontrol1), new propertymetadata(new observablecollection<frameworkelement>()));      public observablecollection<frameworkelement> secondcollection     {         { return (observablecollection<frameworkelement>)getvalue(secondcollectionproperty); }         set { setvalue(secondcollectionproperty, value); }     }      // using dependencyproperty backing store secondcollection.  enables animation, styling, binding, etc...     public static readonly dependencyproperty secondcollectionproperty =         dependencyproperty.register("secondcollection", typeof(observablecollection<frameworkelement>), typeof(usercontrol1), new propertymetadata(new observablecollection<frameworkelement>()));      public observablecollection<frameworkelement> lastcollection     {         { return (observablecollection<frameworkelement>)getvalue(lastcollectionproperty); }         set { setvalue(lastcollectionproperty, value); }     }      // using dependencyproperty backing store lastcollection.  enables animation, styling, binding, etc...     public static readonly dependencyproperty lastcollectionproperty =         dependencyproperty.register("lastcollection", typeof(observablecollection<frameworkelement>), typeof(usercontrol1), new propertymetadata(new observablecollection<frameworkelement>()));  } 

usage:

<window x:class="wpfapplication8.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:local="clr-namespace:wpfapplication8"         title="mainwindow" height="350" width="525" name="ui">     <grid>         <local:usercontrol1 >             <local:usercontrol1.firstcollection>                 <label />             </local:usercontrol1.firstcollection>             <local:usercontrol1.secondcollection>                 <label />             </local:usercontrol1.secondcollection>             <local:usercontrol1.lastcollection>                 <label />             </local:usercontrol1.lastcollection>         </local:usercontrol1>     </grid> </window> 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -