question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SelectingItemsControl missing default control styling

See original GitHub issue

Should work as similar to using a ItemsControl for displaying data, albeit if you want a barebone minimal control without any of the selection visual found in the ListBox control but still have the ability to control your own visual when an item is selected.

Example scenario:

        <SelectingItemsControl
            AutoScrollToSelectedItem="True"
            Grid.IsSharedSizeScope="True"
            ItemsSource="{Binding}"
            SelectedItem="{Binding Selected}">
            <SelectingItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid Margin="0,0,0,8">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="LabelColumn" />
                            <ColumnDefinition Width="25" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <HighlightTextBlock
                            Grid.Column="0"
                            HighlightText="{Binding Key.Selection}"
                            SelectionIndex="{Binding Key.SelectionIndex, Mode=TwoWay}"
                            Text="{Binding Key.Value}" />
                        <HighlightTextBlock
                            Grid.Column="2"
                            HighlightText="{Binding Value.Selection}"
                            Opacity="0.6"
                            SelectionIndex="{Binding Value.SelectionIndex, Mode=TwoWay}"
                            Text="{Binding Value.Value}" />
                    </Grid>
                </DataTemplate>
            </SelectingItemsControl.ItemTemplate>
        </SelectingItemsControl>

I’ve had to manually added a control style copied from ItemsControl.


    <ControlTheme x:Key="{x:Type SelectingItemsControl}" TargetType="SelectingItemsControl">
        <Setter Property="Template">
            <ControlTemplate>
                <Border
                    Padding="{TemplateBinding Padding}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding CornerRadius}">
                    <ItemsPresenter
                        Name="PART_ItemsPresenter"
                        AreHorizontalSnapPointsRegular="{TemplateBinding AreHorizontalSnapPointsRegular}"
                        AreVerticalSnapPointsRegular="{TemplateBinding AreVerticalSnapPointsRegular}"
                        ItemsPanel="{TemplateBinding ItemsPanel}" />
                </Border>
            </ControlTemplate>
        </Setter>
    </ControlTheme>

Issue Analytics

  • State:open
  • Created 5 months ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wieslawsoltescommented, Apr 26, 2023

There are two problems with this:

  • SelectingItemsControl doesn’t specify an item container type, so how would selected items be marked as selected? For example if one’s ItemsSource contains a list of strings then the created containers would be ContentPresenters. How would a ContentPresenter visually indicate that it’s selected?
  • SelectingItemsControl provides no user interaction handling, so even if you got selection displaying, the user wouldn’t be able to interact with the control.

I fear by making this control have a visual representation but one which doesn’t actually indicate selection, we’d be confusing things even more. It would probably make more sense to make the control abstract IMO.

I use a lot the SelectingItemsControl and each time I have to do custom template based on ItemsControl. It is really useful control please don’t make it abstract. It serves great use case between ItemsControl and ListBox

1reaction
grokyscommented, Apr 26, 2023

There are two problems with this:

  • SelectingItemsControl doesn’t specify an item container type, so how would selected items be marked as selected? For example if one’s ItemsSource contains a list of strings then the created containers would be ContentPresenters. How would a ContentPresenter visually indicate that it’s selected?
  • SelectingItemsControl provides no user interaction handling, so even if you got selection displaying, the user wouldn’t be able to interact with the control.

I fear by making this control have a visual representation but one which doesn’t actually indicate selection, we’d be confusing things even more. It would probably make more sense to make the control abstract IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SelectingItemsControl.cs
Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET Foundation community project. - Avalonia/src/Avalonia.
Read more >
Convert Most DirectProperty Occurrences to StyledProperty ...
We didn't, no. I have a WIP which converts SelectedItem and SelectedIndex in SelectingItemsControl to styled properties, but everything breaks ...
Read more >
ComboBox Class - Avalonia UI Framework - API
public class ComboBox : SelectingItemsControl, IAvaloniaObjectDebug, INotifyPropertyChanged ... Gets or sets the font style used to draw the control's text.
Read more >
MenuItem Class - Avalonia UI Framework - API
Raised when the control is attached to a rooted visual tree. Inherited from Visual ... Occurs when the styled element has finished initialization....
Read more >
MenuItem Class - Typedescriptor
A menu item control. ↳, HeaderedSelectingItemsControl Base Class. ↳, SelectingItemsControl ... Fluent: Add missing MenuItem Header styles #4457.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found