简体   繁体   English

将组合框添加到XAML中的功能区控件

[英]Adding combobox to Ribbon Control in XAML

I have a WPF Application with a Ribbon Control . 我有一个带有Ribbon Control的WPF应用程序。 I want to add a ComboBox , to show the logged in user next to the help button. 我想添加一个ComboBox ,以在帮助按钮旁边显示已登录的用户。 But when I try to add the ComboBox , it is created as a Tab . 但是,当我尝试添加ComboBox ,它将创建为Tab

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <Ribbon x:Name="RibbonWin" SelectedIndex="0" Margin="0,0,0,113">
        <Ribbon.HelpPaneContent>
            <RibbonButton SmallImageSource="Images\help.png"></RibbonButton>
        </Ribbon.HelpPaneContent>
        <RibbonComboBox>
            <ComboBoxItem Content="Test1"/>
        </RibbonComboBox>
        <RibbonTab Header="Home" KeyTip="H" Margin="0,0,0,-1" >
            <RibbonGroup x:Name="ClipboardGroup" Header="Clipboard">
                <RibbonMenuButton LargeImageSource="Images\paste.jpg" Label="Paste" KeyTip="V">
                    <RibbonMenuItem ImageSource="Images\paste.jpg" Header="Keep Text Only" KeyTip="T"/>
                    <RibbonMenuItem ImageSource="Images\paste.jpg" Header="Paste Special..." KeyTip="S"/>
                </RibbonMenuButton>
                <RibbonButton SmallImageSource="Images\cut.jpg" Label="Cut" KeyTip="X" />
                <RibbonButton SmallImageSource="Images\copy.jpg" Label="Copy" KeyTip="C" />
            </RibbonGroup>
            <RibbonGroup x:Name="Questions" Header="Questions And Answers">
                <RibbonMenuButton LargeImageSource="Images\Question.jpg" Label="Questions" KeyTip="V">
                    <RibbonMenuItem ImageSource="Images\paste.jpg" Header="Add Question" KeyTip="T"/>
                    <RibbonMenuItem ImageSource="Images\paste.jpg" Header="Paste Special..." KeyTip="S"/>
                </RibbonMenuButton>
                <RibbonButton SmallImageSource="Images\Save.jpg" Label="Save" KeyTip="X" />
                <RibbonButton SmallImageSource="Images\Add.jpg" Label="Add" KeyTip="C" />
            </RibbonGroup>
        </RibbonTab>
        <RibbonTab Header="Insert" KeyTip="I">
        </RibbonTab>
        <RibbonTab Header="PageLayout" KeyTip="L">
        </RibbonTab>
    </Ribbon>
</Grid>

Also is there a way to remove the the Application Menu ComboBox on the left that is created by default. 还有一种方法可以删除默认情况下创建的左侧“ Application Menu ComboBox

Put a RibbonApplicationMenu into the ApplicationMenu-property and set its Visibility to 'Collapsed'. 将RibbonApplicationMenu放入ApplicationMenu属性,并将其可见性设置为'Collapsed'。 This will not remove the application menu, but at least it is not longer visible. 这不会删除应用程序菜单,但至少不再可见。 There is not other way to hide it. 没有其他方法可以隐藏它。

The ComboBox must be inserted into a RibbonTab, so a RibbonTab will be created implicitly if you do not specify anyone. ComboBox必须插入RibbonTab中,因此如果您不指定任何人,则将隐式创建RibbonTab。

The following example demonstrates how to hide the application menu and insert a combo box: 下面的示例演示如何隐藏应用程序菜单并插入组合框:

<Ribbon>
    <Ribbon.ApplicationMenu>
        <RibbonApplicationMenu Visibility="Collapsed"></RibbonApplicationMenu>
    </Ribbon.ApplicationMenu>  
    <RibbonTab>
        <RibbonGroup>
            <RibbonComboBox></RibbonComboBox>
        </RibbonGroup>
    </RibbonTab>
</Ribbon>

I got it from my friend, this might help you Create your own template and add it to Ribbon HelpPaneContentTempalte 我是从朋友那里得到的,这可能会帮助您创建自己的模板并将其添加到功能区HelpPaneContentTempalte

   <Ribbon.HelpPaneContentTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Height="24">
                        <ToggleButton x:Name="btn" >
                            <TextBlock Text="Operator"/>
                        </ToggleButton>

                        <Popup IsOpen="{Binding IsChecked, ElementName=btn}" x:Name="Popup" StaysOpen="False" Placement="Bottom" 
                                   PlacementTarget="{Binding ElementName=btn}" Height="120" Width="150" HorizontalOffset="-90" >
                            <Popup.Resources>
                                <Style  x:Key="LinkButton"  TargetType="Button">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="Button">
                                                <TextBlock>
                                                        <ContentPresenter />
                                                </TextBlock>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Foreground" Value="Blue" />
                                    <Style.Triggers>
                                        <Trigger Property="IsMouseOver" Value="true">
                                            <Setter Property="Foreground" Value="Red" />
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </Popup.Resources>
                            <Border BorderBrush="Gray" BorderThickness="2" Background="White" >
                                <StackPanel Orientation="Vertical">
                                    <StackPanel Orientation="Horizontal" Height="50">
                                        <Image Source="Images\UserPhoto.png" Height="30"/>
                                        <StackPanel VerticalAlignment="Center">
                                            <TextBlock Text="Operator" FontSize="16"  Margin="10,0,0,0"/>
                                            <TextBlock Text="Operator@xxx.com" FontSize="10" Foreground="DarkGray" Margin="10,0,0,0"/>
                                        </StackPanel>
                                    </StackPanel>
                                    <Separator Background="LightGray"/>
                                    <StackPanel Height="30">
                                        <Button x:Name="btnAccountSettings" Content="Account Settings" Style="{StaticResource LinkButton}"  Width="100" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"></Button>
                                    </StackPanel>
                                    <Separator Background="LightGray"/>
                                    <StackPanel Height="30">
                                        <Button x:Name="btnSwitchAccount" Content="Switch Account" Style="{StaticResource LinkButton}"  Width="100" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"></Button>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </Popup>
                        <ContentPresenter Content="{TemplateBinding Property= ContentControl.Content}" />
                    </StackPanel>

                </DataTemplate>
            </Ribbon.HelpPaneContentTemplate>

            <Ribbon.HelpPaneContent>
                <RibbonButton x:Name="btnHelp" SmallImageSource="Images\help.png" />
            </Ribbon.HelpPaneContent>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM