<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
…
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
…
</Grid>
</ControlTemplate>
Альтернативой предыдущего шаблона управления XAML является следующий пример в коде C # .
var rootGrid = new FrameworkElementFactory(typeof(Grid));
var controlTemplate = new ControlTemplate(typeof(TreeViewItem))
{
VisualTree = rootGrid
};
Как прикрепить VisualStateGroup
в версии с выделенным кодом? Я предполагаю, что мне нужно нацелиться FrameworkElementFactory
. Метод FrameworkElementFactory.AppendChild()
ожидает другого FrameworkElementFactory
.