c# - How to initialize readonly item collection with resource in XAML -


suppose have control readonly items collection. can initialize collection using collection syntax:

<something>     <something.items>         <item />         <item />     </something.items> </something> 

suppose have collection in resources , want initialize control it:

<window.resources>     <itemcollectionclass x:key="collection">         <item />         <item />     </itemcollectionclass> </window.resources> 

how it? <something items="{staticresource collection}" /> doesn't work since it's trying set collection instance, not initialize it.

you can initialize collection objectdataprovider:

<window.resources>   <itemcollectionclass x:key="collection">     <item />     <item />   </itemcollectionclass>    <objectdataprovider x:key="..." objecttype="{x:type local:something}">     <objectdataprovider.constructorparameters>       <staticresource resourcekey="collection" />     </objectdataprovider.constructorparameters>   </objectdataprovider> </window.resources /> 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -