Click here to Skip to main content
15,851,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a main window that contains a user control. The user control looks like this:

XML
<Grid x:Name="LayoutRoot" removed="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="5*"/>
        <RowDefinition Height="75*"/>
        <RowDefinition Height="20*"/>
    </Grid.RowDefinitions>
    <Canvas Grid.Row="0" Background="AliceBlue" ClipToBounds="True" x:Name="TitleCanvas"/>
    <Canvas Grid.Row="1" Background="LightGreen" ClipToBounds="True" x:Name="DrawCanvas"/>
    <Canvas Grid.Row="2" Background="Pink" ClipToBounds="True" x:Name="KeyCanvas"/>
</Grid>


My main window has a SizeChanged event handler which redraws the user control. It all works fine if I resize the window by dragging the edges, but if I resize using maximise or restore my user control doesn't redraw properly.

If I refresh or manually resize after the maximise or restore, the control redraws properly, just not immediately following the maximise or restore.

What is going on?
Posted
Comments
Varsha Ramnani 22-Jan-14 4:54am    
I don't get why you are using SizeChanged event handler to redraw the user control?
Grid is a fluid layout type so if the parent window's size is changed then the usercontrol size also gets changed and is calculated according to the parameters in Grid...
& it works fine for me anyway i change the size without sizechanged event handler.
your usercontrol belongs to Main window where you have implemented SizeChanged event right?
Kyudos 22-Jan-14 14:37pm    
This is just the framework for the control - the actual contents of each canvas are drawn in code, hence I need to redraw when changing size. The height and width of the control are bound to its containing element (a border), which lives in a grid in the main window. When the app opens (Normal Window) the control renders correctly (contents centered on the DrawCanvas). If I Maximise, the DrawCanvas content doesn't resize or recenter, if I then Restore the content again redraws incorrectly.
Varsha Ramnani 22-Jan-14 23:50pm    
Why use border as a containing element why not another Grid or even stackpanel?
Kyudos 23-Jan-14 6:20am    
Does it make any difference? Its only a border because that's what it was when I inherited it. Looked at this some more, it seems like the control still has the "normal" size when maximised, then gets the 'maximised' size when restored again.
Varsha Ramnani 23-Jan-14 9:32am    
actually it doesn't matter if the border is in main grid...
what is the content that you are drawing on canvas using code?
I checked ActualHeight and ActualWidth of usercontrol at the time of SizeChanged it is new one with maximise/restore or draging to resize.
how are you calculating the size of the content being drawn on canvas?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900