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 Width Problem

Expander Width Problem

Scheduled Pinned Locked Moved WPF
wpfcsswcfhelpquestion
2 Posts 2 Posters 5 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 trying to create a ListBox, with it's ItemTemplate being an expander, which itself has a list in it. Here's a pic of what I'm trying to accomplish. [Pic](https://1drv.ms/u/s!AlkRTpT49yCMmgxTy4tnD-TMpXa1?e=nEvqc0) I added colors around each item to highlight what's happening. Here's the XAML

    <ListBox Grid.Row="2"
    Grid.Column="1"
    x:Name="outerList"
    Margin="2,2,2,2"
    Background="Transparent"
    ItemsSource="{Binding RecentItemSections}"
    SelectedItem="{Binding SelectedRecentItemSection}"
    HorizontalAlignment="Stretch"
    BorderBrush="Yellow"
    BorderThickness="2">

    <ListBox.ItemTemplate>
    
        <DataTemplate>
    
            <Expander IsExpanded="{Binding IsSectionExpanded}"
                        x:Name="expander"
                        HorizontalAlignment="Stretch"
                        BorderBrush="Red"
                        BorderThickness="2">
    
                <Expander.Header>
                    <TextBlock Text="{Binding SectionName}"
                                Foreground="White" 
                                Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                    AncestorType={x:Type ListBoxItem}}, Path=ActualWidth}"/>
                </Expander.Header>
                            
                <ListBox ItemsSource="{Binding RecentItems}"
                            BorderBrush="Green"
                            BorderThickness="5"
                            Margin="2,0,20,0">
    
                    <ListBox.ItemTemplate>
                        <DataTemplate>
    
                            <Border BorderBrush="MediumAquamarine"
                                    BorderThickness="2">
    
                                <StackPanel Orientation="Vertical"
                                        HorizontalAlignment="Stretch">
    
                                    <TextBlock Text="{Binding ItemName}"
                                            FontSize="12"
                                            Margin="2"/>
    
                                    <TextBlock Text="{Binding ItemLocation}"
                                            FontSize="10"
                                            Margin="2,0,2,2"/>
    
                                </StackPanel>
    
                            </Border>
    
    L 1 Reply Last reply
    0
    • K Kevin Marois

      I'm trying to create a ListBox, with it's ItemTemplate being an expander, which itself has a list in it. Here's a pic of what I'm trying to accomplish. [Pic](https://1drv.ms/u/s!AlkRTpT49yCMmgxTy4tnD-TMpXa1?e=nEvqc0) I added colors around each item to highlight what's happening. Here's the XAML

      <ListBox Grid.Row="2"
      Grid.Column="1"
      x:Name="outerList"
      Margin="2,2,2,2"
      Background="Transparent"
      ItemsSource="{Binding RecentItemSections}"
      SelectedItem="{Binding SelectedRecentItemSection}"
      HorizontalAlignment="Stretch"
      BorderBrush="Yellow"
      BorderThickness="2">

      <ListBox.ItemTemplate>
      
          <DataTemplate>
      
              <Expander IsExpanded="{Binding IsSectionExpanded}"
                          x:Name="expander"
                          HorizontalAlignment="Stretch"
                          BorderBrush="Red"
                          BorderThickness="2">
      
                  <Expander.Header>
                      <TextBlock Text="{Binding SectionName}"
                                  Foreground="White" 
                                  Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
                                      AncestorType={x:Type ListBoxItem}}, Path=ActualWidth}"/>
                  </Expander.Header>
                              
                  <ListBox ItemsSource="{Binding RecentItems}"
                              BorderBrush="Green"
                              BorderThickness="5"
                              Margin="2,0,20,0">
      
                      <ListBox.ItemTemplate>
                          <DataTemplate>
      
                              <Border BorderBrush="MediumAquamarine"
                                      BorderThickness="2">
      
                                  <StackPanel Orientation="Vertical"
                                          HorizontalAlignment="Stretch">
      
                                      <TextBlock Text="{Binding ItemName}"
                                              FontSize="12"
                                              Margin="2"/>
      
                                      <TextBlock Text="{Binding ItemLocation}"
                                              FontSize="10"
                                              Margin="2,0,2,2"/>
      
                                  </StackPanel>
      
                              </Border>
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should know what the maximum header width will be; set the .Width accordingly. (The framework doesn't know beforehand).

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      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