如何在WPF TreeView中应用多个样式

时间:2018-04-07 06:53:58

标签: c# wpf

我是WPF的初学者,需要帮助。

  

问题:   我在表单上有2个树视图,需要在2对树视图比较中应用2种不同的样式。

我们有什么方法可以做到这一点吗?

我有2个Tree View看起来像这样

<TreeView x:Name="Source1PermissionTreeView" ScrollViewer.VerticalScrollBarVisibility="Visible" Height="630" Width="890" >
<TreeView.Resources>

    <DataTemplate DataType="{x:Type entities:SharePointUser}">
        <DockPanel>
            <CheckBox />
            <Image Source="E:\SWorking\SharePointSecurityApps\SharePointSecurityApps\SharePointSecurityApps.WPF\Images\user.png"/>
            <TextBlock Text="{Binding Path=Title}"/>
        </DockPanel>
    </DataTemplate>

    <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type entities:SitePermission}">
        <DockPanel>
            <CheckBox />
            <Image Source="E:\SWorking\SharePointSecurityApps\SharePointSecurityApps\SharePointSecurityApps.WPF\Images\sitepermission.png"/>
            <TextBlock Text="{Binding Path=Title}"></TextBlock>
        </DockPanel>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type entities:SharePointGroup}">
        <DockPanel>
            <CheckBox />
            <Image Source="E:\SWorking\SharePointSecurityApps\SharePointSecurityApps\SharePointSecurityApps.WPF\Images\group.png"/>
            <TextBlock Text="{Binding Path=Title}"/>
        </DockPanel>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type entities:SharePointList}">
        <DockPanel>
            <CheckBox />
            <Image Source="E:\SWorking\SharePointSecurityApps\SharePointSecurityApps\SharePointSecurityApps.WPF\Images\List.PNG"/>
            <TextBlock Text="{Binding Path=Title}"/>
        </DockPanel>
    </HierarchicalDataTemplate>

    <HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type entities:SharePointSite}">
        <DockPanel>
            <CheckBox />
            <Image Source="E:\SWorking\SharePointSecurityApps\SharePointSecurityApps\SharePointSecurityApps.WPF\Images\Site.png"/>
            <TextBlock Text="{Binding Path=Title}"/>
        </DockPanel>
    </HierarchicalDataTemplate>
</TreeView.Resources>  

如何在树状视图中应用样式?

0 个答案:

没有答案