[英]RadListBox selected border color WPF
I'm working on a WPF
application with telerik
controls. 我正在使用带有telerik
控件的WPF
应用程序。
I'm using RadListBox
which is generated in run time according to number of records. 我正在使用RadListBox
,它根据记录数在运行时生成。 So, if i have 10 records in my collection 10 RadListBox will be shown in the application. 因此,如果我的集合中有10条记录,则10 RadListBox将显示在应用程序中。 When i select each RadListBox
a detailed view of the BindedItem will be shown in the nearby panel. 当我选择每个RadListBox
时,附近面板中将显示RadListBox
的详细视图。 Only one RadListBox
can be selected at a time. 一次只能选择一个RadListBox
。
When i select the RadListBox now its showing a gray background which is not visible and the users are not sure which is selected among the 10. 当我现在选择RadListBox时,它显示灰色的背景,这是不可见的,并且用户不确定在10个之中选择了哪个。
Now i need to set a border for the selected RadListBox
. 现在,我需要为选定的RadListBox
设置边框。 So whenever the user selects a RadListBox
the selected ListBox border should be red in color. 因此,每当用户选择RadListBox
,选定的ListBox边框应为红色。
Is there anyway that i can access the Selected RadListBox
and its Border
property? 无论如何,我可以访问Selected RadListBox
及其Border
属性吗?
.XAML Code: .XAML代码:
<telerik:RadListBox Grid.Column="0" Grid.Row="0" Margin="0,25,0,0" BorderThickness="1" BorderBrush="#FFCBD8E8" ItemsSource="{Binding MCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, ValidatesOnDataErrors=True}" ItemTemplate="{StaticResource ImageDataTemplate}" ItemContainerStyle="{StaticResource DraggableListBoxItem}" DragEnter="lseries_DragEnter" DragLeave="ls_DragLeave" Style="{StaticResource myListboxStyle}" SelectedItem="{Binding SSeries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" telerik:StyleManager.Theme="Windows8" PreviewKeyDown="RadListBox_PreviewKeyDown" MouseDoubleClick="l_MouseDoubleClick" PreviewMouseDown="RadListBox_PreviewMouseLeftButtonDown" SelectionChanged="Mt_SelectionChanged">
</telerik:RadListBox>
Image Data Template: 图像数据模板:
<DataTemplate x:Key="ImageDataTemplate">
<Border BorderThickness="2" BorderBrush="#FF21A2DE" CornerRadius="2" VerticalAlignment="Top">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="20" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<TextBlock x:Name="SeriesNo" Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Istre, Mode=TwoWay, Source={StaticResource MViewModel}}" Value="False">
<Setter Property="Text" Value="{Binding SNumber}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Istre, Mode=TwoWay, Source={StaticResource MViewModel}}" Value="True">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" HorizontalAlignment="Center">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Istre, Mode=TwoWay, Source={StaticResource MViewModel}}" Value="False">
<Setter Property="Text" Value="{Binding RDNumber}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Istre, Mode=TwoWay, Source={StaticResource MViewModel}}" Value="True">
<Setter Property="Text" Value="{Binding SeriesNumber}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<Image x:Name="viewImage" Grid.Row="2" Stretch="Uniform" Height="100" Width="135" Source="{Binding DisplayImage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, ValidatesOnDataErrors=True}" Visibility="Visible" />
<TextBlock x:Name="viewText" Grid.Row="2" VerticalAlignment="Center" Height="100" HorizontalAlignment="Center" />
</Grid>
</Border>
</DataTemplate>
Image of the list of RadListBox: RadListBox列表的图像:
You need something like this in your ImageDataTemplate: 您在ImageDataTemplate中需要以下内容:
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType=telerik:RadListBoxItem, AncestorLevel=1}}" Value="True">
<Setter Property="BorderBrush" Value="Red"/>
</DataTrigger>
</Style.Triggers>
<Setter Property="BorderBrush" Value="#FF21A2DE"/>
</Style>
</Border.Style>
Don't forget to remove BorderBrush setter from Border creation line. 不要忘记从Border创建行中删除BorderBrush setter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.