• 如何重写Xceed.Wpf.AvalonDock LayoutItem在Header右键菜单的关闭命令


    定义资源:

     <ResourceDictionary>
        <xcad:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        <ContextMenu x:Key="DocumentContextMenu">
            <MenuItem Command="{Binding Path=Model.CloseCommand}" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="关闭" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
    ....

    完整代码:

    <xcad:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
        <ContextMenu x:Key="DocumentContextMenu">
            <MenuItem Command="{Binding Path=CloseCommand}" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="关闭" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
            <MenuItem Command="{Binding Path=CloseAllButThisCommand}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="除此之外全部关闭" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
    
            <MenuItem Command="{Binding Path=CloseAllCommand}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="全部关闭" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
            <MenuItem Command="{Binding Path=FloatCommand}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="漂浮" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
            <MenuItem Command="{Binding Path=DockAsDocumentCommand}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="停靠成标签式文档" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
            <MenuItem Command="{Binding Path=NewHorizontalTabGroupCommand}" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <MenuItem.Icon>
                    <Image Source="Images/HTabGroup.png" Stretch="Uniform" Width="14" />
                </MenuItem.Icon>
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="新建水平标签分组" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
    
            <MenuItem Command="{Binding Path=NewVerticalTabGroupCommand}" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <MenuItem.Icon>
                    <Image Source="Images/VTabGroup.png" Stretch="Uniform" Width="14" />
                </MenuItem.Icon>
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="新建垂直标签分组" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
            <MenuItem Command="{Binding Path=MoveToNextTabGroupCommand}" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="移动到下一个标签组" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
            <MenuItem Command="{Binding Path=MoveToPreviousTabGroupCommand}" Visibility="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
                <MenuItem.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="移动到上一个标签组" />
                    </DataTemplate>
                </MenuItem.HeaderTemplate>
            </MenuItem>
        </ContextMenu>
    View Code

     注意这里的Model.CloseCommand的Model其实是DockingManager的DocumentsSource集合中的一项,该项对应一个含有CloseCommand属性的类实例,这样写其实就相当于覆盖掉原有CloseCommand

    <xcad:DockingManager x:Name="dockingManager"
          AllowMixedOrientation="True"
          DocumentContextMenu="{StaticResource DocumentContextMenu}"
          BorderBrush="Black"
          FontFamily="Microsoft YaHei"
          DocumentClosing="dockingManager_OnDocumentClosing"
          DocumentsSource="{Binding Path=PanelsModel.Panels}"
          BorderThickness="1">
    如DocumentContextMenu="{StaticResource DocumentContextMenu}"所示,直接指定DocumentContextMenu就ok了。

    写得有点乱,权当是个简记。
  • 相关阅读:
    谜题92:双绞线
    谜题91:序列杀手
    谜题90:荒谬痛苦的超类
    谜题89:泛型迷药
    谜题88:原生类型的处理
    谜题87:紧张的关系
    谜题86:有毒的括号垃圾
    谜题85:惰性初始化
    谜题84:被粗暴地中断
    easyUi DataGrid
  • 原文地址:https://www.cnblogs.com/144823836yj/p/12677179.html
Copyright © 2020-2023  润新知