【问题标题】:Windows 7 Ribbon: How to specify "Four buttons, two big, two small"?Windows 7 功能区:如何指定“四个按钮,两个大,两个小”?
【发布时间】:2010-08-04 15:25:34
【问题描述】:

布局组时,Windows 功能区框架支持some predefined layouts。其中一种需要四个按钮的布局称为FourButtons

此布局支持 3 种不同的尺寸,LargeMediumSmall。在每种情况下,它都会给出布局:

中等

现在我在我的 xml 文件中使用 FourButtons 预定义模板:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://schemas.microsoft.com/windows/2009/Ribbon">
   ...
   <Application.Views>
      <Ribbon>
         ...
         <Ribbon.Tabs>
            <Tab CommandName="tabHome">
               <Group CommandName="grpActivity" SizeDefinition="FourButtons">
                  <Button CommandName="cmdStartWorking" />
                  <Button CommandName="cmdStopWorking" />
                  <Button CommandName="cmdPrint" />
                  <Button CommandName="cmdDuplicateTicket" />
               </Group>
            </Tab>
         </Ribbon.Tabs>

      </Ribbon>
   </Application.Views>
</Application>

你可以看到这条线

<Group CommandName="grpActivity" SizeDefinition="FourButtons">

指定FourButtons 布局模板。

而我的布局是FourButtons

除了我不想要 FourButtons 布局,我想要“四个按钮,两个大两个小”。

同理有ThreeButtons-OneBigAndTwoSmall:

还有一个FiveButtons

我想要一个FourButtons-TwoBigTwoSmall,我可以手动制作模型:

不幸的是,声明式编程that Microsoft invented for creating custom layouts 让我作为程序员感到困惑。

谁能破译页面底部的声明性语言示例并想出一个 FourButton-TwoBigTwoSmall 模板?

注意:所有漂亮的图形、格式、链接和东西都用来吸引松鼠——它们喜欢闪亮的图形。如果你真的读到这里,我可以实际上使用你的帮助。

【问题讨论】:

    标签: windows-7 ribbon windows-ribbon-framework scenic-ribbon uiribbon


    【解决方案1】:

    你应该使用 BigButtonsAndSmallButtonsOrInputs SizeDefinition

    例如

          <Group CommandName="cmdGroupBatch" SizeDefinition="BigButtonsAndSmallButtonsOrInputs">
            <ControlGroup>
              <Button CommandName="cmdButtonGetBatch" />
              <Button CommandName="cmdButtonPutBatch" />
            </ControlGroup>
            <ControlGroup>
              <Button CommandName="cmdButtonSaveBatch" />
              <Button CommandName="cmdButtonDiscartBatch" />
            </ControlGroup>
          </Group>
    

    只需检查一下,如果您的 Group 在 Tab.ScalingPolicy 中有 Size="Large"。

    【讨论】:

    • 其实我终于明白了。这绝对不是一件容易的事。但我会给你一个几乎同样好的解决方案。而且因为你是唯一一个在 41 次观看中做出回应的人。
    【解决方案2】:

    我终于弄明白了。

    首先是控制图,它要求组有(在这种情况下)四个按钮。通过在ControlNameMap 中有四个条目,我们要求使用这个大小定义的组实际上有四个按钮。

    <ControlNameMap>
       <ControlNameDefinition Name="button1"/>
       <ControlNameDefinition Name="button2"/>
       <ControlNameDefinition Name="button3"/>
       <ControlNameDefinition Name="button4"/>
    </ControlNameMap>
    

    四个按钮被赋予别名:

    • button1
    • button2
    • button3
    • button4

    以便它们可以在后面的定义中被引用。首先是 Large 模板:

    <GroupSizeDefinition Size="Large">
        <ControlSizeDefinition ControlName="button1" ImageSize="Large" IsLabelVisible="true" />
        <ControlSizeDefinition ControlName="button2" ImageSize="Large" IsLabelVisible="true" />
        <ColumnBreak ShowSeparator="true"/>
        <ControlSizeDefinition ControlName="button3" ImageSize="Large" IsLabelVisible="true" />
        <ControlSizeDefinition ControlName="button4" ImageSize="Large" IsLabelVisible="true" />
    </GroupSizeDefinition>
    

    这会导致两个大按钮、一个分隔符和另外两个大按钮。

    中等模板:

    <GroupSizeDefinition Size="Medium">
        <ControlSizeDefinition ControlName="button1" ImageSize="Large" IsLabelVisible="true" />
        <ControlSizeDefinition ControlName="button2" ImageSize="Large" IsLabelVisible="true" />
        <ColumnBreak ShowSeparator="true"/>
        <Row>
            <ControlSizeDefinition ControlName="button3" ImageSize="Small" IsLabelVisible="true" />
        </Row>
        <Row>
            <ControlSizeDefinition ControlName="button4" ImageSize="Small" IsLabelVisible="true" />
        </Row>
    </GroupSizeDefinition>
    

    导致两个大按钮,一个分隔符,然后是两行(每行包含一个小按钮)。

    模板:

    <GroupSizeDefinition Size="Small">
        <Row>
            <ControlSizeDefinition ControlName="button1" ImageSize="Small" IsLabelVisible="true" />
            <ControlSizeDefinition ControlName="button3" ImageSize="Small" IsLabelVisible="false" />
        </Row>
        <Row>
            <ControlSizeDefinition ControlName="button2" ImageSize="Small" IsLabelVisible="true" />
            <ControlSizeDefinition ControlName="button4" ImageSize="Small" IsLabelVisible="false" />
        </Row>
    </GroupSizeDefinition>
    

    导致出现两行,每行有两个小按钮。


    把它们放在一起:

    <Group CommandName="grpActivity" >
        <SizeDefinition>
            <ControlNameMap>
                <ControlNameDefinition Name="button1"/>
                <ControlNameDefinition Name="button2"/>
                <ControlNameDefinition Name="button3"/>
                <ControlNameDefinition Name="button4"/>
            </ControlNameMap>
            <GroupSizeDefinition Size="Large">
                <ControlSizeDefinition ControlName="button1" ImageSize="Large" IsLabelVisible="true" />
                <ControlSizeDefinition ControlName="button2" ImageSize="Large" IsLabelVisible="true" />
                <ColumnBreak ShowSeparator="true"/>
                <ControlSizeDefinition ControlName="button3" ImageSize="Large" IsLabelVisible="true" />
                <ControlSizeDefinition ControlName="button4" ImageSize="Large" IsLabelVisible="true" />
            </GroupSizeDefinition>
            <GroupSizeDefinition Size="Medium">
                <ControlSizeDefinition ControlName="button1" ImageSize="Large" IsLabelVisible="true" />
                <ControlSizeDefinition ControlName="button2" ImageSize="Large" IsLabelVisible="true" />
                <ColumnBreak ShowSeparator="true"/>
                <Row>
                    <ControlSizeDefinition ControlName="button3" ImageSize="Small" IsLabelVisible="true" />
                </Row>
                <Row>
                    <ControlSizeDefinition ControlName="button4" ImageSize="Small" IsLabelVisible="true" />
                </Row>
            </GroupSizeDefinition>
            <GroupSizeDefinition Size="Small">
                <Row>
                    <ControlSizeDefinition ControlName="button1" ImageSize="Small" IsLabelVisible="true" />
                    <ControlSizeDefinition ControlName="button3" ImageSize="Small" IsLabelVisible="false" />
                </Row>
                <Row>
                    <ControlSizeDefinition ControlName="button2" ImageSize="Small" IsLabelVisible="true" />
                    <ControlSizeDefinition ControlName="button4" ImageSize="Small" IsLabelVisible="false" />
                </Row>
            </GroupSizeDefinition>
        </SizeDefinition>
    
        <Button CommandName="cmdStartWorking" />
        <Button CommandName="cmdStopWorking" />
        <Button CommandName="cmdPrint" />
        <Button CommandName="cmdDuplicateTicket" />
    </Group>
    

    【讨论】:

      猜你喜欢
      • 2016-12-18
      • 2023-02-09
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 2019-11-23
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多