Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Expander in ListBoxItem Width Problem

Expander in ListBoxItem Width Problem

Scheduled Pinned Locked Moved WPF
helpphpwpfwcfcom
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    I'm working on this control[^]. The code is in this repository[^]. It has a listbox filled with expanders. I can't seem to get the expanders to size horizontally corrrectly. The expanders should horizontally fill inside the listboxitem. This is what I'm gettting[^] I tried binding the width of the expander to the width of the listboxitem, but it gives some strange results. See this[^] I found some Google hits that say to set the width of the expanders header content. Here's one example[^]. I've tried this and it has the same affect as in my second picture. And, even more strange, when I do try to bind the width, the vertical scrollbar on the right is visible and enabled, but no longer drags to scroll. Mouse wheel scrolling is unafffected Anyone know the right way to do this?

    If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

    Richard DeemingR 1 Reply Last reply
    0
    • K Kevin Marois

      I'm working on this control[^]. The code is in this repository[^]. It has a listbox filled with expanders. I can't seem to get the expanders to size horizontally corrrectly. The expanders should horizontally fill inside the listboxitem. This is what I'm gettting[^] I tried binding the width of the expander to the width of the listboxitem, but it gives some strange results. See this[^] I found some Google hits that say to set the width of the expanders header content. Here's one example[^]. I've tried this and it has the same affect as in my second picture. And, even more strange, when I do try to bind the width, the vertical scrollbar on the right is visible and enabled, but no longer drags to scroll. Mouse wheel scrolling is unafffected Anyone know the right way to do this?

      If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Remove the Width binding and the HorizontalAlignment on the ctrls:NavigationPane element. Instead, set the HorizontalContentAlignment property on the ListBox.

          <Setter Property="MaxHeight" Value="300"/>
          <Setter Property="Template">
              <Setter.Value>
                  <ControlTemplate TargetType="{x:Type ctrls:NavigationPane}">
                      <Grid>
                          <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="\*"/>
                          </Grid.ColumnDefinitions>
      
                          <Expander Header="{Binding Header, RelativeSource={RelativeSource TemplatedParent}}"
                                    Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}"
                                    Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}"
                                    BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
                                    BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"
                                    ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                                    IsExpanded="True">
      
                              <Grid>
                                  <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}"
                                           ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                           ScrollViewer.VerticalScrollBarVisibility="Auto"
                                           Margin="2"
                                           BorderBrush="Transparent"
                                           BorderThickness="0">
                                      <ListBox.ItemTemplate>
                                          <DataTemplate>
      
                                              <TextBlock Text="{Binding Caption}"
          </x-turndown>
      

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      K 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Remove the Width binding and the HorizontalAlignment on the ctrls:NavigationPane element. Instead, set the HorizontalContentAlignment property on the ListBox.

            <Setter Property="MaxHeight" Value="300"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ctrls:NavigationPane}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="\*"/>
                            </Grid.ColumnDefinitions>
        
                            <Expander Header="{Binding Header, RelativeSource={RelativeSource TemplatedParent}}"
                                      Padding="{Binding Padding, RelativeSource={RelativeSource TemplatedParent}}"
                                      Margin="{Binding Margin, RelativeSource={RelativeSource TemplatedParent}}"
                                      BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}}"
                                      BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}}"
                                      ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                      ScrollViewer.VerticalScrollBarVisibility="Auto"
                                      IsExpanded="True">
        
                                <Grid>
                                    <ListBox ItemsSource="{Binding Items, RelativeSource={RelativeSource TemplatedParent}}"
                                             ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                             ScrollViewer.VerticalScrollBarVisibility="Auto"
                                             Margin="2"
                                             BorderBrush="Transparent"
                                             BorderThickness="0">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
        
                                                <TextBlock Text="{Binding Caption}"
            </x-turndown>
        
        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        That did it. I spent hours trying to figure that out. It seems in this case all the properties have to be just right. Thanks

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups