c# - Initialize Collection of DataTemplates in XAML -
i have dependencyproperty
public observablecollection<datatemplate> wizardtemplatecollection { { return (observablecollection<datatemplate>)getvalue(wizardtemplatecollectionproperty); } set { setvalue(wizardtemplatecollectionproperty, value); } } // using dependencyproperty backing store myproperty. enables animation, styling, binding, etc... public static readonly dependencyproperty wizardtemplatecollectionproperty = dependencyproperty.register("wizardtemplatecollection", typeof(observablecollection<datatemplate>), typeof(customwizardcontrol), new propertymetadata(new observablecollection<datatemplate>()));
and want this:
<custom:customwizardcontrol> <custom:customwizardcontrol.wizardtemplatecollection> <datatemplate> <rectangle></rectangle> </datatemplate> <datatemplate> <rectangle></rectangle> </datatemplate> <datatemplate> <rectangle></rectangle> </datatemplate> </custom:customwizardcontrol.wizardtemplatecollection> </custom:customwizardcontrol>
what datatype need? or how can initialize observablecollection
in xaml
.
additional:
public class customwizardcontrol : control {}
your customwizardcontrol
class must inherit depenedencyobject
or 1 of derived types example uielement
or control
:
public class customwizardcontrol : control { public observablecollection<datatemplate> wizardtemplatecollection { { return (observablecollection<datatemplate>)getvalue(wizardtemplatecollectionproperty); } set { setvalue(wizardtemplatecollectionproperty, value); } } ... }
this works:
public class customwizardcontrol : control { public customwizardcontrol() { wizardtemplatecollection = new observablecollection<datatemplate>(); } public observablecollection<datatemplate> wizardtemplatecollection { { return (observablecollection<datatemplate>)getvalue(wizardtemplatecollectionproperty); } set { setvalue(wizardtemplatecollectionproperty, value); } } public static readonly dependencyproperty wizardtemplatecollectionproperty = dependencyproperty.register("wizardtemplatecollection", typeof(observablecollection<datatemplate>), typeof(customwizardcontrol), new propertymetadata(null)); }
<local:customwizardcontrol x:name="ctrl"> <local:customwizardcontrol.wizardtemplatecollection> <datatemplate> <rectangle></rectangle> </datatemplate> <datatemplate> <rectangle></rectangle> </datatemplate> <datatemplate> <rectangle></rectangle> </datatemplate> </local:customwizardcontrol.wizardtemplatecollection> </local:customwizardcontrol>
<textblock text="{binding wizardtemplatecollection.count, elementname=ctrl}" />
Comments
Post a Comment