Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
- /// <summary>
- /// Это коллекция для заполнения ListBox
- /// </summary>
- private ObservableCollection<Animal> _Animals;
- public ObservableCollection<Animal> Animals
- {
- get { return _Animals; }
- set
- {
- if (_Animals == value) return;
- _Animals = value;
- PropertyChanged(this, new PropertyChangedEventArgs(nameof(Animals)));
- }
- }
- /// <summary>
- /// Текущее выбранное животное в ListBox
- /// </summary>
- private Animal _CurrentAnimal;
- public Animal CurrentAnimal
- {
- get { return _CurrentAnimal; }
- set
- {
- if (_CurrentAnimal == value) return;
- _CurrentAnimal = value;
- PropertyChanged(this, new PropertyChangedEventArgs(nameof(CurrentAnimal)));
- }
- }
- <ListBox ItemsSource="{Binding Animals, Mode=TwoWay}"
- SelectedItem="{Binding CurrentAnimal}"/>
- private void SelectClient(object sender, MouseEventArgs e)
- {
- var index = listboxFolder.Items.IndexOf(((ListBoxItem)sender).DataContext);
- MessageBox.Show(index.ToString());
- }
- listboxFolder.SelectionChanged += (sender, e) => {
- var id = (listboxFolder.SelectedItem as [Ваш класс клиента]).id;
- MessageBox.Show(id.ToString());
- };
Add Comment
Please, Sign In to add comment