I have a Window with my user control and I would like to make usercontrol width equals window width. How to do that?
The user control is a horizontal menu and contains a grid with three columns:
<ColumnDefinition Name='LeftSideMenu' Width='433'/> <ColumnDefinition Name='Middle' Width='*'/> <ColumnDefinition Name='RightSideMenu' Width='90'/>
That is the reason I want the window width, to stretch the user control to 100% width, with the second column relative.
EDIT:
I am using a grid, there is the code for Window:
<Window x:Class='TCI.Indexer.UI.Operacao' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:tci='clr-namespace:TCI.Indexer.UI.Controles' Title=' ' MinHeight='550' MinWidth='675' Loaded='Load' ResizeMode='NoResize' WindowStyle='None' WindowStartupLocation='CenterScreen' WindowState='Maximized' Focusable='True' x:Name='windowOperacao'> <Canvas x:Name='canv'> <Grid> <tci:Status x:Name='ucStatus'/> <!-- the control which I want to stretch in width --> </Grid> </Canvas> </Window>
You need to make sure your usercontrol hasn’t set it’s width in the usercontrol’s xaml file. Just delete the Width=’…’ from it and you’re good to go!
EDIT: This is the code I tested it with:
SOUserAnswerTest.xaml:
Window1.xaml: