0
我想從radtreeview採取高光背景。我創建了一個樣式來做到這一點,但我一直在收到錯誤和異常,例如「Items collection must be empty」。如果我註釋掉應用程序的風格,那麼我知道它是問題的原因。我對WPF相當陌生,我確信我只是不明白如何使用樣式。 感謝您的幫助。這是代碼。我需要幫助實現一種風格到我的radTreeView
<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>
一旦我修改它,它不會讓我保存文件。是否真的沒有其他方式來做到這一點?這太瘋狂了.. – JLott
對不起,錯過了這個評論 - 這可能是因爲該文件位於Telerik的TFS源代碼控制下,並且在將文件添加到安裝文件夾之前,它們不會從文件中刪除只讀標誌。轉到文件的屬性並刪除只讀標誌。 – XAMeLi