Answer the question
In order to leave comments, you need to log in
WPF. C#. How to know which item is selected in a ListBox if the list is styled?
There is a list
<ListBox x:Name="listboxFolder" BorderThickness="0" ItemsSource="{Binding Path=ClientsOnlineList, UpdateSourceTrigger=PropertyChanged}" Margin="0,50,0,10" HorizontalAlignment="Left" Width="301" Background="#FFD0E6C5" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="SelectClient"></EventSetter>
<Setter Property="Margin" Value="5"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Cursor" Value="Hand"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Green"/>Bold"/>
<Setter Property="FontSize" Value="23"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate >
<DataTemplate >
<TextBlock Text="{Binding UserName}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Answer the question
In order to leave comments, you need to log in
There is a SelectedItem property . You can see here .
Is it hard to think and google first?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question