简体   繁体   中英

RadListBox selected border color WPF

I'm working on a WPF application with telerik controls.

I'm using RadListBox which is generated in run time according to number of records. So, if i have 10 records in my collection 10 RadListBox will be shown in the application. When i select each RadListBox a detailed view of the BindedItem will be shown in the nearby panel. Only one RadListBox can be selected at a time.

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.

Now i need to set a border for the selected RadListBox . So whenever the user selects a RadListBox the selected ListBox border should be red in color.

Is there anyway that i can access the Selected RadListBox and its Border property?

.XAML Code:

 <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:

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM