【发布时间】:2019-10-12 00:28:07
【问题描述】:
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
…
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
…
</Grid>
</ControlTemplate>
之前的 XAML 控件模板的替代方案是 code-behind C# 中的以下示例。
var rootGrid = new FrameworkElementFactory(typeof(Grid));
var controlTemplate = new ControlTemplate(typeof(TreeViewItem))
{
VisualTree = rootGrid
};
如何在代码隐藏版本中附加VisualStateGroup?我假设我需要定位FrameworkElementFactory。方法 FrameworkElementFactory.AppendChild() 需要另一个 FrameworkElementFactory。
【问题讨论】:
标签: c# wpf code-behind controltemplate