Is there something like a WPF list without a choice?

The application that I am developing has a kind of accordion consisting of expanders, but each exapnder acts independently, and not only allows you to open one open element at the same time. Each expander is associated with an item in the collection in the view model.

My solution now is to use a list and then bind the itemsource list to the collection and have an element template displaying the contents of the expander and exapnders.

The problem is that listbox treats each expander as an element (obviously) and allows you to select and select. The selection is a little ugly and can be turned off, but the selection causes some problems because it causes the list to scroll to show as much of the extended expander as possible.

Is there a WPF control that looks a bit like a glass pane (maybe) that will allow me to link the contained controls using element templates, but without selection and selection?

enter image description here

<ListBox Grid.Row="0" Grid.Column="0" Width="Auto" SelectionMode="Single" ItemsSource="{Binding Path=MeasurementSources}"> <ListBox.ItemTemplate> <DataTemplate> <Expander Header="{Binding Name}" IsEnabled="{Binding Available}"> <ListBox Width="Auto" SelectionMode="Single" ItemsSource="{Binding Path=Measurements}" SelectedItem="{Binding Path=SelectedMeasurement}"> <ListBox.ItemTemplate> <DataTemplate> <WrapPanel> <TextBlock Text="{Binding Name}" FontWeight="Bold" /> <TextBlock Text=" "/> <TextBlock Text="{Binding Created}"/> </WrapPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Expander> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 
+4
source share
3 answers

If you want List-like capabilities with no choice, you should use ItemsControl - by the way, the base class Selector , which, in turn, is the base class ListBox

It all just gets

 <ItemsControl Width="Auto" ItemsSource="{Binding Measurements}" <ItemsControl.ItemTemplate> <DataTemplate> <WrapPanel> <TextBlock Text="{Binding Name}" FontWeight="Bold" /> <TextBlock Text=" "/> <TextBlock Text="{Binding Created}"/> </WrapPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> 

Obviously, you cannot bind the selected item in this case.

+18
source

Best solution for me:

  <Style TargetType="{x:Type ListBoxItem}"> <Style.Resources> <!-- With focus --> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /> <!-- Without focus --> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /> <!-- Text foreground --> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" /> </Style.Resources> <Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter> </Style> 

and I found it a few months ago somewhere on stackoverflow :)

0
source

This is useful information that I did not understand.

http://msdn.microsoft.com/library/windows/apps/hh780657.aspx

Note ItemsControl is the base class for several common collections of controls, including ListView, GridView, FlipView, ListBox, and ComboBox Controls. These examples use ListView and GridView, but the information is usually applied to ItemsControls.

In other words, using ItemsControl really is the way to solve my problem, because using ListBox and then trying to disable selection and selection function really turns it into its own base class.

0
source

Source: https://habr.com/ru/post/1493381/


All Articles