代码之家  ›  专栏  ›  技术社区  ›  David Veeneman

WPF拆分按钮?[关闭]

  •  20
  • David Veeneman  · 技术社区  · 15 年前

    我刚刚花了一个非常令人沮丧的下午在谷歌搜索一个商业级的WPF。 SplitButton 控制将在 ToolBar . 一 分裂按钮 您可以在其中单击 Button 要执行默认操作,或单击右侧的一个小三角形以获得可选操作的下拉菜单)。

    我在网上找到了几个(包括一个关于codeproject的,还有两个关于codeplex的)。它们都不能在 工具栏 --它们要么根本不显示,要么没有工具栏按钮样式。我甚至看了一些商业产品,比如actipro的弹出按钮(在他们的sharedlibrary dll中)。同样的问题。

    是的,我已经看到了所有关于创建一个帖子是多么容易的帖子。创建一个坏的是很容易的,但创建一个外观和工作方式与 分裂按钮 在Outlook或Visual Studio中,如果释放鼠标按钮,下拉菜单不会消失。

    所以,我的问题是:有商业级的吗? 分裂按钮 在工具栏中工作的是开源的还是商业的?我不是在找一个控件,它是每年订阅某人控件库1500美元的控件的一部分,但是如果有一个合理的定价 拆分按钮 我很想找到它。

    8 回复  |  直到 7 年前
        1
  •  7
  •   Reed Copsey    15 年前

    我所知道的唯一真正的“商业级”拆分按钮是 Syncfusion ,作为其功能区控件的一部分包含(尽管它也在功能区之外工作)。

    我记得有人说过 this implementation 如果你想找一些免费的东西的话,这是相当有用和完整的。

        2
  •  6
  •   Alex_P    15 年前

    另一个很好的免费实施方案似乎无所不包:

    http://huydinhpham.blogspot.com/2008/09/wpf-drop-down-and-split-button.html

    • “拆分”按钮可以在工具栏中使用,并且具有适当的工具栏样式。如果需要,也可以重新设计。
    • 下拉菜单是通过其自身的属性公开的,即splitbutton可以将其自己的上下文菜单与下拉菜单分开(尽管看起来不合理,但在某些情况下它可能很有用,例如右键单击工具栏中的按钮时弹出的工具栏上下文菜单)。
    • 下拉菜单是标准的ContextMenu,即内容可以进行数据绑定,菜单项可以重新设置样式等。
    • 拆分按钮的主部分和下拉部分都有与其关联的命令属性。
        3
  •  3
  •   huseyint    14 年前

    对于WPF和Silverlight over Delay的博客,有一个非常好的拆分按钮实现:

    Banana SplitButton (A WPF-specific fix for SplitButton and some code analysis improvements for the Silverlight version, too)

        4
  •  3
  •   Benoit Blanchon    11 年前

    这个 Extended WPF Toolkit Community Edition (免费)有一个不错的 SplitButton (而且它有一个 DropDownButton 同样)

    SplitButton screen capture

    <xctk:SplitButton Content="Click Me">
        <xctk:SplitButton.DropDownContent>
            <xctk:ColorCanvas />
        </xctk:SplitButton.DropDownContent>
     </xctk:SplitButton>
    
        5
  •  2
  •   Anderson Imes    15 年前

    我不知道你在一个拆分按钮中到底在寻找什么,但是这个关于如何创建一个拆分按钮的视频非常完整,并且制作了一个完美的拆分按钮。

    http://windowsclient.net/learn/video.aspx?v=3929

    我知道你不想要一个教程,但我以前用过这个,你无法区分它和Outlook中的不同。

        6
  •  1
  •   codymanix    15 年前

    我想你的意思是一个下拉按钮。 在menuitem“statysopenonclick”上有一个布尔属性,可以解决您的问题。

        7
  •  0
  •   KornMuffin    9 年前

    我正在寻找相同的,只是滚动我自己的(您将需要样式符合您的喜好(以匹配工具栏),您可以重构它/将其转换为自定义控件…等)

    <StackPanel x:Name="Split" Orientation="Horizontal">
        <Button Command="{Binding MainCommand}">
            <StackPanel>
                <Image Source="{StaticResource MainCommandImage}"/>
                <TextBlock>MainCommand</TextBlock>
            </StackPanel>
        </Button>
        <Separator HorizontalAlignment="Left" Width="1" VerticalAlignment="Stretch" Margin="0,5"/>
        <CheckBox Width="16" IsThreeState="False">
            <Grid>
                <Path Fill="Black" Data="{StaticResource DownArrowGeometry}"
                      Stretch="Uniform" Height="6" Width="6" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <Popup x:Name="popupOptions" AllowsTransparency="True" PopupAnimation="Fade" StaysOpen="False" 
                       Placement="Bottom" PlacementTarget="{Binding ElementName=Split}" HorizontalOffset="-3"
                       IsOpen="{Binding RelativeSource={RelativeSource AncestorType={x:Type CheckBox}, AncestorLevel=1}, Path=IsChecked}">
                    <StackPanel>
                        <StackPanel>
                            <Image Source="{StaticResource SubCommandImage1}"/>
                            <TextBlock>SubCommand1</TextBlock>
                         </StackPanel>
                        <StackPanel>
                            <Image Source="{StaticResource SubCommandImage2}"/>
                            <TextBlock>SubCommand2</TextBlock>
                         </StackPanel>
                    </StackPanel>
                </Popup>
            </Grid>
        </CheckBox>
    </StackPanel>
    
        8
  •  0
  •   aydjay Farhad Jabiyev    7 年前

    使用wpf toolkit split按钮显示上下文菜单是相当直接的。在窗口资源中添加上下文菜单。在窗口加载-将上下文菜单绑定到拆分按钮,然后像通常那样使用上下文菜单。

    它确实需要添加到WPF工具箱中,因为这个按钮的大多数使用案例是复制旧的winform splitt按钮。

    enter image description here

    <Window x:Class="SplitButtonTesting.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <ContextMenu x:Key="contextMenu" IsOpen="{Binding IsOpen}">
            <MenuItem Header="One" />
            <MenuItem Header="Two" />
            <MenuItem Header="More...">
                <MenuItem Header="One" />
                <MenuItem Header="Two" />
            </MenuItem>
        </ContextMenu>
    </Window.Resources>
    <DockPanel>
    
        <Menu DockPanel.Dock="Top" x:Name="ApplicationMenu">
    
            <xctk:SplitButton x:Name="SplitButton" Content="Main Button" DropDownContent="{x:Null}" />
    
        </Menu>
        <Border />
    
    </DockPanel>
    

    代码落后:

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    
    namespace SplitButtonTesting
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                SetupSplitButton();
            }
    
            public void SetupSplitButton()
           {
               var menu = this.Resources["contextMenu"] as ContextMenu;
    
               menu.PlacementTarget = SplitButton;
    
                menu.Placement = PlacementMode.Bottom;
                menu.DataContext = SplitButton;
            }
        }
    }