How to set width to 100% in WPF

Askmaan
Askmaan
2 Points
1 Posts

Hi,

I am beginner in WPF. I am developing desktop application in xaml design as :

<Window x:Class="NOC_PDFTool.MainWindow" 
Title="main" Height="350" Width="525" Icon="images/pdfsmall.ico">
 
<Grid Name="grid_Main">
 
<Menu x:Name="menu" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="100"> 
 
 
<MenuItem Header="Help">
 
<MenuItem Header="View Help"/>
 
<MenuItem Header="About PDF tool"/>
 
</MenuItem>
 
<MenuItem Header="Exit"/>
 
</Menu>
 
</Grid>
</Window>

When window maximize or minimize menu width remain same. Please help.

 

Views: 12286
Total Answered: 1
Total Marked As Answer: 0
Posted On: 01-Jul-2015 20:51

Share:   fb twitter linkedin
Answers
Brian
Brian
2376 Points
13 Posts
         

Hi Askmaan,

Just try this code : 

<Menu x:Name="menu" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="{Binding ElementName=grid_Main, Path=ActualWidth}">

Then your XAML code will be as: 

<Window x:Class="NOC_PDFTool.MainWindow" 
Title="main" Height="350" Width="525" Icon="images/pdfsmall.ico">
 
<Grid Name="grid_Main">
 
<Menu x:Name="menu" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Width="{Binding ElementName=grid_Main, Path=ActualWidth}">  
 
<MenuItem Header="Help">
 
<MenuItem Header="View Help"/>
 
<MenuItem Header="About PDF tool"/>
 
</MenuItem>
 
<MenuItem Header="Exit"/>
 
</Menu>
 
</Grid>
</Window>

 

Posted On: 01-Jul-2015 20:53
 Log In to Chat