在WPF中的菜单按钮上调用用户控件 [英] Calling an user control on menu button in wpf

查看:72
本文介绍了在WPF中的菜单按钮上调用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户控件(menuUserControl)应该在窗口顶部显示为菜单项,从菜单按钮调用.
在下面的主窗口代码中给出

I want that user control(menuUserControl) should be seen on top of window as menu item ,calling from menu button.
given below main window code

<window 

	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

	xml:lang="en-US"

	xmlns:abc="clr-namespace:abc"

	xmlns:d="http://schemas.microsoft.com/expression/blend/2006"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    xmlns:local="clr-namespace:abc"

	x:Class="abc.Window1"

	x:Name="Window"

	Title="abc">
    <border>
        <border>
            <grid x:name="LayoutRoot" xmlns:x="#unknown">
                    <dockpanel>
                    <abc:menuusercontrol1 visibility="Visible" margin="0,31.096,109.8,-29.096" x:name="menuUserControl1" xmlns:abc="#unknown" />
                    <grid dockpanel.dock="Top">
                            <grid>
                                <grid.columndefinitions>
                                    <columndefinition width=".300*" />
                                    <columndefinition width=".700*" />
                                </grid.columndefinitions>
                                <Label DockPanel.Dock="Top"  

                                    Grid.Column="1"

                                     >abc
                                </Label>
                                <Button Grid.Column="1" >
                                    r
                                </Button>
                                <Button Grid.Column="1"/>
                                               <Button Grid.Column="1">                          
                        </grid>
                            <grid>
                                <grid.columndefinitions>
                                    <columndefinition width="59*" />
                                    <columndefinition width="634*" />
                                    <columndefinition width="85*" />
                                </grid.columndefinitions>
                                <Button>
           
                        Grid.Column="2">
                                    ?
                                </Button>
                            </grid>
                          
                            <Button>
                                <Image/>
                            
                             
                            </Button>
                       
                        </grid>
                     
                        <abc:mystatusbarcontrol dockpanel.dock="Bottom" xmlns:abc="#unknown" />
                        
                        <dockpanel dockpanel.dock="Left">
            
                            <border dockpanel.dock="Left">
                         
                                <grid>
                                    <grid.rowdefinitions>
                                        <rowdefinition height=".060*" />
                                        <rowdefinition height=".060*" />
                                        <rowdefinition height=".600*" />
                                        <rowdefinition height=".165*" />
                                        <rowdefinition height=".08*" />
                                    </grid.rowdefinitions>
                                    <border grid.row="0"> 
                                        <dockpanel> 
                                            <togglebutton>
                                          DockPanel.Dock="Right" >
                                                <Label>
                                                    <Label>
                                                        <Label.RenderTransform>
                                                            <rotatetransform angle="16" centerx="29" centery="0"></rotatetransform>
                                                        </Label.RenderTransform>
                                                    </Label>
                                                </Label>
   
                            

                                            </togglebutton>
                   
                                            <textblock>
                        </textblock></dockpanel>
                                    </border>
                                    <border grid.row="1">

                                        <dockpanel>
                                            <textblock />
                        </dockpanel>
                                    </border>
                                    <scrollviewer grid.row="2">
                                        <stackpanel>
                                        </stackpanel>
                                    </scrollviewer>
                                    <grid grid.row="3">
                                        <grid.rowdefinitions>
                                            <rowdefinition />
                                            <rowdefinition />
                                            <rowdefinition />
                                        </grid.rowdefinitions>
                                        <Button Grid.Row="0">
                                            <stackpanel>
                                                <textblock>
                                                    iagnosis
                                                </textblock>
  						    </stackpanel>
                                        </Button>
                                        <Button Grid.Row="1">
                                            <stackpanel>
                                                <textblock>
                                                    <underline>F</underline>irmware
                                                </textblock>
  						    </stackpanel>
                                        </Button>
                                        <Button  Grid.Row="2"> 
                                            <stackpanel>
                                                <textblock>
                                                    Reader <underline>S</underline>ettings
                                                </textblock>
  						    </stackpanel>
                                        </Button>
                                    </grid>
                                    <border grid.row="4">
                                        <Image  />
                                 
                                    </border>
                                    <abc:mysidebarcontrol xmlns:abc="#unknown">
                         Grid.Row="0" Grid.RowSpan="5">
                                    </abc:mysidebarcontrol>
                                </grid>
                            </border>
                                      <abc:resizingcustomcontrol dockpanel.dock="Left" xmlns:abc="#unknown">
                                <abc:resizingcustomcontrol.resources>
                                                    <border />
                                </abc:resizingcustomcontrol.resources>
                            </abc:resizingcustomcontrol>
            
                            <border grid.column="1" dockpanel.dock="Right">
                                <grid name="contentGrid">
                                    <Image Grid.Row="0" Grid.RowSpan="2" ></Image>
                                </grid>
                            </border>
                        </dockpanel>
                    </dockpanel>
                    <!-- Top PANEL -->
                
            </grid> 
        </border>
    </border>   
</window>

推荐答案



尽管您提供的代码几乎无法使用(与XAML无关,其中"border","grid"和您列出的大多数其他元素都不存在),但可以实现您的愿望(应该看到"menuUserControl"顶部")是在menueusercontrol1的定义中设置
Hi,

allthough your provided code is almost unusable (it has nothing to do with XAML, where "border", "grid" and most of the other elements you listed don''t exist), the solution to your wish ("menuUserControl should be seen on top") is to set
DockPanel.Dock="Top"

.

不幸的是,我不知道,从菜单按钮调用"是什么意思,因为您的按钮后面都没有命令或代码,也没有调用控件.因此,如果仍然存在问题,也许您可​​以对此进行详细说明.

干杯
于尔根(Jürgen)

in the definition of menueusercontrol1.

Unfortunately I have no idea, what you mean by "calling from menu button" as none of your buttons has a command or code behind and controls aren''t called. So maybe you elaborate a bit on that, if there still is a problem.

Cheers
Jürgen


这篇关于在WPF中的菜单按钮上调用用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆