R
R
Roman Rakzin2016-10-22 02:22:07
WPF
Roman Rakzin, 2016-10-22 02:22:07

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>

ClientsOnlineList - List. Contains fields UserName, id, etc.
When selecting a list, how can I find out which ClientsOnlineList.Id was selected? Since the list is styled, I'm lost in the links and how can I find out the selected element?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Silin, 2016-10-22
@byme

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 question

Ask a Question

731 491 924 answers to any question