在WPF中的usercontrol内动态应用样式的TreeViewItems

时间:2016-07-26 11:41:08

标签: c# wpf xaml user-controls

我想从我的MainWindow.xaml中将样式应用于usercontrol中的所有RadTreeViewItems。我在资源字典中有与RadTreeViewItem相关的样式,当我尝试将它应用于usercontrol时,它会抛出异常。

TreeItemStyle

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                >
    <Style x:Key="GenericTreeItemStyle"  TargetType="{x:Type telerik:RadTreeViewItem}" BasedOn="{StaticResource {x:Type telerik:RadTreeViewItem}}" >
        <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}" />
        <Setter Property="IsExpanded" Value="{Binding IsExpanded,Mode=TwoWay}" />
        <Setter Property="IsInEditMode" Value="{Binding IsInEditMode,Mode=TwoWay}" />
        <Setter Property="FontWeight" Value="{Binding NodeFontLook,Mode=OneWay}"/>
        <Setter Property="FontStyle" Value="{Binding NodeFontStyle,Mode=OneWay}"/>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="FontWeight" Value="Bold"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>

MainWindow.xaml中的用法

<UC:TreeUserControl Name="RepositoryTree"  Style="{StaticResource GenericTreeItemStyle}"/>

提供异常

  

&#34;&#39; RadTreeViewItem&#39; TargetType与元素的类型不匹配&#39; TreeUserControl&#39;。&#34;

如何将样式应用于MainWindow.xaml的UserControl内部控件?

0 个答案:

没有答案