Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting ItemsPanel property for ListBox (ItemsControl) from style does not work #8086

Closed
wieslawsoltes opened this issue May 5, 2022 · 0 comments · Fixed by #9677
Closed
Labels

Comments

@wieslawsoltes
Copy link
Collaborator

wieslawsoltes commented May 5, 2022

Describe the bug
Setting ItemsPanel property for ListBox (ItemsControl) from style does not work (when switching class during runtime after initial panel was set)

To Reproduce

Click on ToggleSwitch so wide class is applied to ListBox and ItemsPanel (and presumably ItemTemplate) should change to WrapPanel

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:collections="clr-namespace:System.Collections;assembly=netstandard"
             xmlns:system="clr-namespace:System;assembly=netstandard"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="250"
             x:Class="HelloAvaloniaNdc.Views.MainView">
    <Grid Margin="8" RowDefinitions="Auto, Auto, *, Auto">
        <Grid.Styles>
            <Style Selector="ListBox.normal">
                <Setter Property="ItemTemplate">
                    <DataTemplate DataType="system:String">
                        <Panel Height="30" Background="Red"/>
                    </DataTemplate>
                </Setter>
            </Style>
            <Style Selector="ListBox.wide">
                <Setter Property="ItemTemplate">
                    <DataTemplate DataType="system:String">
                        <Panel Height="30" Width="100" Background="Green"/>
                    </DataTemplate>
                </Setter>
                <Setter Property="ItemsPanel">
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </Setter>
            </Style>
        </Grid.Styles>
        <ListBox Name="ListBox"
                 Classes.normal="{Binding !#Switch.IsChecked, Mode=OneWay}"
                 Classes.wide="{Binding #Switch.IsChecked, Mode=OneWay}"
                 Grid.Row="2">
            <ListBox.Items>
                <collections:ArrayList>
                    <x:String>0</x:String>
                    <x:String>1</x:String>
                    <x:String>2</x:String>
                    <x:String>3</x:String>
                    <x:String>4</x:String>
                    <x:String>5</x:String>
                </collections:ArrayList>
            </ListBox.Items>
        </ListBox>
        <ToggleSwitch Name="Switch" IsChecked="False" OnContent="wide" OffContent="normal" Grid.Row="3" />
    </Grid>
</UserControl>

Expected behavior
ItemsPanel should change to WrapPanel

Desktop (please complete the following information):

  • OS: Windows, Mac
  • Version 0.10.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant