How to set ItemsPanelTemplate to a dynamically created Grid in code behind

后端 未结 4 1000
我在风中等你
我在风中等你 2021-01-18 09:20

I\'ve got this UserControl defined in XAML and would like to set the ItemsPanelTemplate dynamically in my code behind class (not in th

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 09:51

    You need to create an ItemsPanelTemplate and set it's VisualTree to a FrameworkElementFactory (deprecated) which creates the Grid, or use the XamlReader to parse a XAML-string which specifies the template.

    This question contains usage examples of both methods (albeit for a different template property).

    An easier method to manipulate the panel at runtime is outlined in this question.

提交回复
热议问题