【问题标题】:I need help implementing a style into my radTreeView我需要帮助在我的 radTreeView 中实现样式
【发布时间】:2012-05-30 14:03:11
【问题描述】:

我想从 radtreeview 中移除高亮背景。我创建了一个样式来执行此操作,但我不断收到错误和异常,例如“项目集合必须为空”。如果我注释掉应用程序的样式,那么我知道这是问题的原因。我对 WPF 相当陌生,而且我确信我还不明白如何使用样式。 谢谢你的帮助。这是代码。

<Grid x:Name="LayoutRoot" Background="Salmon">

        <telerik:RadTreeView x:Name="radTreeView" Margin="8" ItemsSource="{Binding Errors}" Background="Salmon" Style="{StaticResource treeStyle}">
             <Style TargetType="{x:Type telerik:RadTreeViewItem}" x:Name="treeStyle">
                <Setter Property="Focusable" Value="False"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="true">
                        <Setter Property="Background" Value="{x:Null}"/>
                        <Setter Property="BorderBrush" Value="{x:Null}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>


            <telerik:RadTreeView.ItemTemplate>
                 <HierarchicalDataTemplate ItemsSource="{Binding SubItems}" >
                    <Grid Background="Salmon">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>

                        </Grid.RowDefinitions>
                        <TextBlock Text="{Binding Description}" IsHitTestVisible="False" />

                        <ListBox Grid.Row="1" ItemsSource="{Binding Messages}" Margin="20,0,0,0" BorderBrush="#00000000" BorderThickness="0" Background="Salmon" IsHitTestVisible="False" >
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Message}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>

                </HierarchicalDataTemplate>


            </telerik:RadTreeView.ItemTemplate>


        </telerik:RadTreeView>

    </Grid>

</UserControl>

如果你知道这行不通,我也在尝试用样式代码去掉高亮:

<Style TargetType="TreeViewItem">
      <Style.Resources>
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFF"/>
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="#000"/>
     </Style.Resources>  
</Style>

【问题讨论】:

    标签: c# wpf xaml styles radtreeview


    【解决方案1】:

    您会遇到异常,因为您的样式标签实际上是树中的一个项目,并且您设置了 ItemsSource

    &lt;telerik:RadTreeView.ItemContainerStyle&gt;标签包围样式。

    这应该可以解决异常,但它不会给您预期的结果,因为树视图项的控件模板实际上显示了另一个不受Background 属性影响的边框。您将需要更改控件模板。

    Telerik 会在不同版本之间更改样式,因此给您一个错误版本的模板可能对您没有帮助。

    但是,您可以转到 Telerik 的安装文件夹并查找名为“Themes”的文件夹。在那里你会找到一个包含 Telerik 所有主题的解决方案。

    • 选择您使用的那个。
    • 找到树视图的资源字典并将项目的样式和模板复制到您的项目中。
    • 更改 xmlns 定义,确保您拥有样式所依赖的所有画笔和资源。
    • 运行看看样式没问题。
    • 在模板中,找到VisualStatex:Name="MouseOver" 并删除其中的情节提要。

    【讨论】:

    • 一旦我修改了它就不会让我保存文件。真的没有别的办法了吗??这太疯狂了..
    • 抱歉,错过了这条评论——这可能是因为该文件在 Telerik 的 TFS 源代码控制下,并且在将文件添加到安装文件夹之前,他们没有从文件中删除只读标志。转到文件的属性并删除只读标志。
    猜你喜欢
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多