2024年终活动

DevExpress控件使用交流,DevExpress中国社区Dev联系电话 联系电话:023-68661681

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

来源:   发布时间:2015-12-18   浏览:4303次

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


代码: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控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/601.html
扫码咨询
电话咨询
023-68661681
返回
顶部