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. WCF and WF
  4. Set maximum available width for Stackpanel

Set maximum available width for Stackpanel

Scheduled Pinned Locked Moved WCF and WF
wpfcsswcfhelp
3 Posts 3 Posters 0 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.
  • G Offline
    G Offline
    GDavy
    wrote on last edited by
    #1

    I don't do xaml that often, so some (probably) basic stuff bites me in the ass now and then. The small problem I have now is that I can't seem to get a stackpanel take the correct size. This is basicly how the form looks like:

      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
    
       .....
       Here a bunch of controls are added and then come the stackpanels
    
       <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
         And again some controls in the stackpanel
       </StackPanel>
       .....
    

    What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice. I would like that the stackpanel uses the full column-width of the grid. I tried binding the width of the stackpanel to the column, widht like this:

        First name the column where the stackpanel is in
        <Grid.ColumnDefinitions>
          ....
          <ColumnDefinition **x:Name="BindColumn"** Width="Auto"/>
          ....
        &lt;/Grid.ColumnDefinitions&gt;
    
        Then bind to the width like:
        <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" **Width="{Binding ElementName=BindColumn, Path=Width}"**\>
    

    This doesn't work. It doesn't seem like I want something that should be difficult to make it work, so I'm probably offtrack here with my way of thinking. Thanks to anyone if they can put me on the right track again. Greets, Davy

    G A 2 Replies Last reply
    0
    • G GDavy

      I don't do xaml that often, so some (probably) basic stuff bites me in the ass now and then. The small problem I have now is that I can't seem to get a stackpanel take the correct size. This is basicly how the form looks like:

        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
          </Grid.ColumnDefinitions>
      
         .....
         Here a bunch of controls are added and then come the stackpanels
      
         <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
           And again some controls in the stackpanel
         </StackPanel>
         .....
      

      What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice. I would like that the stackpanel uses the full column-width of the grid. I tried binding the width of the stackpanel to the column, widht like this:

          First name the column where the stackpanel is in
          <Grid.ColumnDefinitions>
            ....
            <ColumnDefinition **x:Name="BindColumn"** Width="Auto"/>
            ....
          &lt;/Grid.ColumnDefinitions&gt;
      
          Then bind to the width like:
          <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" **Width="{Binding ElementName=BindColumn, Path=Width}"**\>
      

      This doesn't work. It doesn't seem like I want something that should be difficult to make it work, so I'm probably offtrack here with my way of thinking. Thanks to anyone if they can put me on the right track again. Greets, Davy

      G Offline
      G Offline
      Gideon Engelberth
      wrote on last edited by
      #2

      GDavy wrote:

      What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice.

      does not look as nice as...... what? A StackPanel will always take up only the space it needs for the controls in the stacking direction (in this case, width). Once you decide how the extra space should be used (given to the last control, left blank, shared among all controls, ...), you can determine which other container to use instead.

      1 Reply Last reply
      0
      • G GDavy

        I don't do xaml that often, so some (probably) basic stuff bites me in the ass now and then. The small problem I have now is that I can't seem to get a stackpanel take the correct size. This is basicly how the form looks like:

          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
        
           .....
           Here a bunch of controls are added and then come the stackpanels
        
           <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
             And again some controls in the stackpanel
           </StackPanel>
           .....
        

        What happens is that the stackpanel takes exactly the size needed to fit the controls it has in it, which does not look as nice. I would like that the stackpanel uses the full column-width of the grid. I tried binding the width of the stackpanel to the column, widht like this:

            First name the column where the stackpanel is in
            <Grid.ColumnDefinitions>
              ....
              <ColumnDefinition **x:Name="BindColumn"** Width="Auto"/>
              ....
            &lt;/Grid.ColumnDefinitions&gt;
        
            Then bind to the width like:
            <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" **Width="{Binding ElementName=BindColumn, Path=Width}"**\>
        

        This doesn't work. It doesn't seem like I want something that should be difficult to make it work, so I'm probably offtrack here with my way of thinking. Thanks to anyone if they can put me on the right track again. Greets, Davy

        A Offline
        A Offline
        aj esler
        wrote on last edited by
        #3

        try

        <StackPanel HorizontalAlignment="Stretch">
        ...
        </StackPanel>

        Not sure if this will work though.

        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