如何将菜单拉伸到整个窗口

时间:2014-10-01 17:07:01

标签: c# wpf

我正在使用Microsoft visual studio 2010,wpf应用程序,包括参考动态数据显示地图。

首先,这就是我的项目的样子:

enter image description here

我想控制对象,标签,尤其是工具栏,我希望工具栏可以拉伸所有屏幕水平。它不起作用。 属性horizo​​ntalAligment是“Stretch”。  不知道如何解决它。 我的代码在XAML中:

<Window x:Class="MapSample.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
        Title="כוכב בוהק" 
        HorizontalContentAlignment="Center"
        mc:Ignorable="d"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        d:DesignHeight="702"
        SizeToContent="Manual"
        d:DesignWidth="983"
        WindowState="Maximized" >


    <Grid Cursor="Hand"
          Height="704"
          Width="807">
        <Grid.RowDefinitions>
            <RowDefinition Height="253*" />
            <RowDefinition Height="451*" />
        </Grid.RowDefinitions>

        <Menu Cursor="Hand"
              DockPanel.Dock="Top"
              Margin="0,0,12,185"
              HorizontalContentAlignment="Stretch"
              FlowDirection="RightToLeft"
              VerticalContentAlignment="Stretch"
              Background="Gainsboro"
              FontWeight="Normal">
            <MenuItem Header="קובץ" FontWeight="Bold" FontSize="14">

                <MenuItem  Name="Open"
                           Header="פתח">
                    <MenuItem.ToolTip>
                       פתח קובץ.
                    </MenuItem.ToolTip>
                </MenuItem>

                <MenuItem  Name="Save"
                           Header="שמור">
                    <MenuItem.ToolTip>
                        שמור קובץ.
                    </MenuItem.ToolTip>
                </MenuItem>
                <MenuItem  Name="Options"
                           Header="הגדרות">
                    <MenuItem.ToolTip>
                        הצג הגדרות.
                    </MenuItem.ToolTip>
                </MenuItem>
                <MenuItem  Name="Close"
                           Header="סגור">
                    <MenuItem.ToolTip>
                        סגור תוכנית זו.
                    </MenuItem.ToolTip>
                </MenuItem>
            </MenuItem>

            <MenuItem Header="יצירה"
                      FontWeight="Bold"
                      FontSize="14">
                <MenuItem Header="יצירת גרפים" >
                                <MenuItem Name="CreatGraph"
                                          Header="גרף המציג זמן כפונקציה של דיוק" />
                                <MenuItem    Name="CreatGraph2"
                                             Header=" גרף המציג איכונים העוברים את המפרט מתוך כלל האיכונים שנורו" />
                                <MenuItem    Name="CreatGraph3"
                                             Header=" גרף המציג זמן כפונקציה של מרחק מהמכ'ם למסלול הירי" />
                                <MenuItem    Name="CreatGraph4"
                                             Header=" 'גרף המציג את גרף א' וגרף ג" />
                </MenuItem>
                <MenuItem Header="יצירת מפות">
                    <MenuItem Name="CreatMap1"
                              Header="מפה שתציג נ'צ הנפילה האמיתית מול נ'צ נקודת חיתוך התצפיתנים והמרחק בינהם" />
                    <MenuItem    Name="CreatMap2"
                                 Header=" מפה שתכיל את המכ'ם, האיכון שהתקבל, מיקומי התצפיתנים והאזימוטים שלהם" />
                </MenuItem>

            </MenuItem>
        </Menu>
        <d3:ChartPlotter Name="plotter" Visible="-180,-90,360,180" Height="470" Width="700"
                         MouseLeftButtonDown="plotter_MouseLeftButtonDown"
                         MouseRightButtonDown="plotter_MouseRightButtonDown"
                         Margin="54,117"
                         Grid.RowSpan="2">


            <d3:ChartPlotter.DataTransform>
                <d3:MercatorTransform/>
            </d3:ChartPlotter.DataTransform>

            <d3:Map>
                <d3:OpenStreetMapServer/>           
            </d3:Map>

            <d3:CursorCoordinateGraph  Cursor="Pen"
                                       OpacityMask="Black" />
            <d3:AxisCursorGraph/>
        </d3:ChartPlotter>


        <Label Content=":תוצאות "
               Height="136"
               HorizontalAlignment="Left"
               Margin="-160,118,0,0"
               Name="lbl_resualt_measurement"
               VerticalAlignment="Top"
               Width="196"
               HorizontalContentAlignment="Right"
               Grid.RowSpan="2" />
        <Button Content="הכנס נקודה"
                Height="23"
                HorizontalAlignment="Right"
                Margin="0,74,110,0"
                Name="btn_InsertPoint"
                VerticalAlignment="Top"
                Width="78"
                Click="btn_insertPoint_Click"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Center" />
        <TextBox Visibility="Collapsed"
            Height="23"
                 HorizontalAlignment="Left"
                 Margin="317,74,0,0"
                 Name="txt_Vertical"
                 VerticalAlignment="Top"
                 Width="143"
                 Text="הכנס תחום בציר האנכי"
                 GotFocus="txt_Vertical_GotFocus"
                 HorizontalContentAlignment="Center"
                 VerticalContentAlignment="Center" />
        <TextBox 
            Visibility="Collapsed"
            Height="23"
                 HorizontalAlignment="Left"
                 Margin="466,74,0,0"
                 Name="txt_Horizental"
                 VerticalAlignment="Top"
                 Width="143"
                 Text="הכנס תחום בציר האופקי"
                 GotFocus="txt_Horizental_GotFocus"
                 HorizontalContentAlignment="Center"
                 VerticalContentAlignment="Center" />
        <Label Content=":אזימוטים מתקבלים "
               Height="86"
               HorizontalAlignment="Left"
               Margin="-160,39,0,0"
               Name="lbl_Azimuth"
               VerticalAlignment="Top"
               Grid.Row="1"
               Width="201"
               HorizontalContentAlignment="Right" />
        <Image Height="35"
               HorizontalAlignment="Left"
               Margin="665,26,0,0"
               Name="PushPinImage"
               Stretch="Uniform"
               VerticalAlignment="Top"
               Width="30"
               Source="/MapSample;component/Images/Push_Pin1.png"
               MouseLeftButtonDown="PushPinImage_MouseLeftButtonDown" />
        <Image Height="35"
               HorizontalAlignment="Right"
               Margin="0,26,149,0"
               Name="PolygonImage"
               Stretch="Uniform"
               VerticalAlignment="Top"
               Width="39"
               Source="/MapSample;component/Images/Maps-Polygon-icon.png"
               MouseLeftButtonDown="PolygonImage_MouseLeftButtonDown" />
        <Image Height="35"
               HorizontalAlignment="Left"
               Margin="572,26,0,0"
               Name="MesurmentImage"
               Stretch="Uniform"
               VerticalAlignment="Top"
               Width="41"
               Source="/MapSample;component/Images/Mesurment.ico"
               MouseLeftButtonDown="MesurmentImage_MouseLeftButtonDown" />
        <Image Height="40"
               HorizontalAlignment="Left"
               Margin="524,24,0,0"
               Name="RadiusImage"
               Stretch="Uniform"
               VerticalAlignment="Top"
               Width="42"
               Source="/MapSample;component/Images/CircleCR.png"
               MouseLeftButtonDown="RadiusImage_MouseLeftButtonDown" />
    </Grid>
</Window>

感谢。

1 个答案:

答案 0 :(得分:2)

Menu尽可能地伸展。限制始终由父容器设置。

在这种情况下,您的Menu位于Grid,其宽度为807,因此您Menu的广度不会超过Grid

删除width: 100%上的约束,菜单将拉伸到整个可用空间。

如果您习惯使用HTML,就好像div中的width: 807px元素与{{1}}一样。内部元素不能超出父母的限制。