locked
Having trouble laying out custom button content RRS feed

  • Question

  • I am trying to create a button that has custom content.  I understand how to put custom content in the button but it always seems to be centered in the button.  I want to put something on the left side of the button and something on the right....no matter how wide the button is.  I bet there is an easy way to do this but I can't figure it out.

    Here is an example of what I have tried.  My basic problem is that the main container of the custom button content (the grid container) is not resizing automatically to the width of the button.

    <Button x:Name="ShowHideReportOptionsButton" Grid.Row="2" Grid.Column="0" Height="25" VerticalAlignment="Top" Click="ShowHideReportOptionsButton_Click">

      <Grid Background="Yellow" HorizontalAlignment="Left" VerticalAlignment="Stretch" >

        <TextBlock Text="left" HorizontalAlignment="Left"/>

        <TextBlock Text="right" HorizontalAlignment="Right"/>

      </Grid>

    </Button>

     Thanks so much in advance!!!

     Todd

    Thursday, June 4, 2009 9:26 PM

Answers

  • Hi Todd,

    Try setting the button's HorizontalContentAlignment="Stretch"

    And set the inner grid's HorizontalAlignment="Stretch"

     

    Thursday, June 4, 2009 11:17 PM

All replies

  • Hi Todd,

    Try setting the button's HorizontalContentAlignment="Stretch"

    And set the inner grid's HorizontalAlignment="Stretch"

     

    Thursday, June 4, 2009 11:17 PM
  • Eureka, that solved my problem.  Thank you so much!!

     Todd

    Thursday, June 4, 2009 11:26 PM