question

JohnOstler-6145 avatar image
0 Votes"
JohnOstler-6145 asked ·

Question about HorizontalAlignment.Right on window size changed

Hello. I am making a wpf app. I have a button that is made out of a canvas. I added this button to the child of another canvas and i want it to stay on the right side of the parent and it does with the code I have written but when i change the size of the application the parent gets way bigger and the exit button doesn't stay on the right hand side which is a problem. How can i the child with horizonatal alignment. right on the right hand side always without adding code to a window size changed event? Thanks.

windows-wpf
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Post your xaml

0 Votes 0 ·

1 Answer

DaisyTian-MSFT avatar image
0 Votes"
DaisyTian-MSFT answered ·

You can try to design your xaml like below:

  <Grid Width="{Binding RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor},Path=ActualWidth}" 
               Height="{Binding RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor},Path=ActualHeight}" 
               >
             <Grid.RowDefinitions>
                 <RowDefinition Height="4*"></RowDefinition>
                 <RowDefinition Height="*"></RowDefinition>
             </Grid.RowDefinitions>
             <Canvas Background="Azure" Grid.Row="0">
             </Canvas>
             <Canvas Background="LightPink" Grid.Row="1">
                 <Button Width="50" Content="Exit" Canvas.Right="25" Canvas.Bottom="40" />
             </Canvas>
         </Grid>

The result picture is:


67983-2.gif

Did I misunderstand, if I did, please post your xaml code for me to analyze.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2.gif (349.3 KiB)
· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hey thanks for the help sorry for the late response how do I do this programatically. I need to add a grid to my rectangle then add the exit button after. Is that why horizonatal alignment doesn't work thanks.

0 Votes 0 ·