如何使s WPF菜单看起来像Windows窗体工具条菜单?

时间:2022-09-11 18:51:53

I am new to WPF. And by new I mean I just started it today after getting .net 3.5. I usually do GUI Development in Windows Forms and like the awesome ToolStripMenu. But when I saw the WPF Menu, it was so ugly that it reminded me of my Win32 Api days. Is there any way to change the style of a WPF menu to make it look like a Windows Forms menu?

我是WPF的新手。我的意思是我今天刚开始写。net 3。5。我通常在Windows窗体中进行GUI开发,喜欢很棒的ToolStripMenu。但是当我看到WPF的菜单时,它太丑了,让我想起了我的Win32 Api。有没有办法改变WPF菜单的样式,使它看起来像Windows窗体菜单?

2 个解决方案

#1


6  

try this:

试试这个:

An introduction to styling and templating: http://msdn.microsoft.com/en-us/library/ms745683.aspx

样式和模板介绍:http://msdn.microsoft.com/en-us/library/ms745683.aspx

A new styling for toolbar http://msdn.microsoft.com/en-us/library/aa970772.aspx

工具栏的新样式http://msdn.microsoft.com/en-us/library/aa970772.aspx。

Alternatively search for wpf ToolBar style

或者搜索wpf工具条样式

Edit: Yes - but add a menu like this and the toolbar alters the menu style (paste in new project):

编辑:是的-但是添加这样的菜单和工具栏改变菜单样式(在新项目中粘贴):

<Grid>
<Grid.RowDefinitions>
  <RowDefinition Height="Auto"></RowDefinition>
  <RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ToolBarTray >
  <ToolBar >
  <Menu>
    <MenuItem Header="Hey">
      <MenuItem Header="lo"></MenuItem>
    </MenuItem>
    <MenuItem Header="Ho">
      <MenuItem Header="la"></MenuItem>
    </MenuItem>
  </Menu>
</ToolBar>
</ToolBarTray>

#2


1  

The Menu, like most WPF controls has very little styling by default.

菜单和大多数WPF控件一样,默认情况下样式很少。

But that's just by default, you can add your own styles and outshine WinForms very easily .

但这只是默认的,你可以添加你自己的风格和超越WinForms非常容易。

Just a little starter:

只是一个小起动器:

    <Menu DockPanel.Dock="Top" >
        <Menu.Background>
            <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="White" Offset="0" />
                <GradientStop Color="Blue" Offset="1" />
            </LinearGradientBrush>
        </Menu.Background>
        <MenuItem Header="_File" >

#1


6  

try this:

试试这个:

An introduction to styling and templating: http://msdn.microsoft.com/en-us/library/ms745683.aspx

样式和模板介绍:http://msdn.microsoft.com/en-us/library/ms745683.aspx

A new styling for toolbar http://msdn.microsoft.com/en-us/library/aa970772.aspx

工具栏的新样式http://msdn.microsoft.com/en-us/library/aa970772.aspx。

Alternatively search for wpf ToolBar style

或者搜索wpf工具条样式

Edit: Yes - but add a menu like this and the toolbar alters the menu style (paste in new project):

编辑:是的-但是添加这样的菜单和工具栏改变菜单样式(在新项目中粘贴):

<Grid>
<Grid.RowDefinitions>
  <RowDefinition Height="Auto"></RowDefinition>
  <RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<ToolBarTray >
  <ToolBar >
  <Menu>
    <MenuItem Header="Hey">
      <MenuItem Header="lo"></MenuItem>
    </MenuItem>
    <MenuItem Header="Ho">
      <MenuItem Header="la"></MenuItem>
    </MenuItem>
  </Menu>
</ToolBar>
</ToolBarTray>

#2


1  

The Menu, like most WPF controls has very little styling by default.

菜单和大多数WPF控件一样,默认情况下样式很少。

But that's just by default, you can add your own styles and outshine WinForms very easily .

但这只是默认的,你可以添加你自己的风格和超越WinForms非常容易。

Just a little starter:

只是一个小起动器:

    <Menu DockPanel.Dock="Top" >
        <Menu.Background>
            <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="White" Offset="0" />
                <GradientStop Color="Blue" Offset="1" />
            </LinearGradientBrush>
        </Menu.Background>
        <MenuItem Header="_File" >