DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 示例代码 » DevExpress WPF 15.2代码示例:如何实现工具条合并

DevExpress WPF 15.2代码示例:如何实现工具条合并

作者:   来源:   浏览:Loading...次   发布时间:2015-12-18   评论:0条

本示例演示在不支持自动合并的控件中如何实现工具条的合并操作。


代码:C#  |  版本:15.2.4

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        x:Class="WpfApplication20.MainWindow"
        Title="MainWindow" Height="275" Width="525">
    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <dxb:MainMenuControl Grid.Row="0">
            <dxb:BarButtonItem Content="File"/>
            <dxb:BarButtonItem Content="Settings"/>
            <dxb:BarButtonItem Content="Exit"/>
        </dxb:MainMenuControl>
        <TabControl Grid.Row="1">
            <TabControl.Resources>
                <ControlTemplate x:Key="menuPresenterTemplate" TargetType="ContentControl">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <!--The following MainMenuControl belongs to the name scope implicitly defined for the Window.
                        The Window's name scope is topmost.-->
                        <dxb:MainMenuControl Grid.Row="0" x:Name="elementHost"/>
                        <ContentPresenter  Grid.Row="1"/>
                    </Grid>
                </ControlTemplate>
            </TabControl.Resources>
            <!--Specify the InternalWithInternal merging behavior:  a Tab's elements are only merged with other elements of the same Tab 
                provided that they are defined in parent name scopes 
            -->
            <TabItem Header="Tab 1" dxb:MergingProperties.ElementMergingBehavior="InternalWithInternal">  
                <ContentControl Template="{StaticResource menuPresenterTemplate}">
                    <StackPanel>
                        <!--control 1-->
                        <!--Explicitly define a name scope for the StackPanel.-->
                        <!--Elements of this container will be merged to the 'elementHost' MainMenuControl, as it is defined in the parent name scope-->
                        <StackPanel dxb:BarNameScope.IsScopeOwner="True">
                            <dxb:MainMenuControl>
                                <dxb:BarButtonItem Content="Cut"/>
                                <dxb:BarButtonItem Content="Copy"/>
                                <dxb:BarButtonItem Content="Paste"/>
                            </dxb:MainMenuControl>
                            <TextBox Text="Text 1"/>
                        </StackPanel>
                        <!--control 2-->
                        <!--Explicitly define a name scope for the StackPanel.-->
                        <!--Elements of this container will be merged to the 'elementHost' MainMenuControl, as it is defined in the parent name scope-->
                        <StackPanel dxb:BarNameScope.IsScopeOwner="True">
                            <dxb:MainMenuControl>
                                <dxb:BarButtonItem Content="Left"/>
                                <dxb:BarButtonItem Content="Center"/>
                                <dxb:BarButtonItem Content="Right"/>
                            </dxb:MainMenuControl>
                            <TextBox Text="Text 2"/>
                        </StackPanel>
                    </StackPanel>
                </ContentControl>
            </TabItem>
            <TabItem Header="Tab 2" dxb:MergingProperties.ElementMergingBehavior="InternalWithInternal">
                <ContentControl Template="{StaticResource menuPresenterTemplate}">
                    <!--...-->
                </ContentControl>                
            </TabItem>
        </TabControl>
    </Grid>
</Window>

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/CodeExamples-501.html

关键字: DevExpress WPF 

相关产品: DXperience WPF Subscription

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道