如何在WPF功能区选项卡中使用相同的工具栏?

时间:2012-07-14 02:27:52

标签: wpf xaml ribbon

我是WPF的新手,我正在使用功能区控件。我有三个不同的功能区选项卡,如下面的代码所示。我使用相同的收费栏按钮。我写的方式如下所示,似乎不是一种记忆优化方法。任何人都可以帮助修改代码,以便我可以在所有功能区选项卡中使用相同的工具栏而不重复吗?

        <ribbon:RibbonTab x:Name="HomeTab" 
                          Header="Home">
            <ribbon:RibbonGroup x:Name="Group1" 
                                Header="">
                <ribbon:RibbonButton x:Name="Update1"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Update" />
                <ribbon:RibbonButton x:Name="Register1"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Register" />
                <ribbon:RibbonButton x:Name="Uninstall1"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Uninstall"  />
                <ribbon:RibbonButton x:Name="Invisible1"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Go invisible" Click="Invisible_Click"/>
                <ribbon:RibbonButton x:Name="Help1"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Help" />
                <ribbon:RibbonButton x:Name="Quit1"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Quit" Click="Quit_Click"/>
            </ribbon:RibbonGroup>

        </ribbon:RibbonTab>
        <ribbon:RibbonTab x:Name="LogTab" 
                          Header="Log History">
            <ribbon:RibbonGroup x:Name="Group11" 
                                Header="">
                <ribbon:RibbonButton x:Name="Update2"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Update" />

                <ribbon:RibbonButton x:Name="Regiter2"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Register" />
                <ribbon:RibbonButton x:Name="Uninstall2"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Uninstall" />
                <ribbon:RibbonButton x:Name="Invisible2"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Go invisible" Click="Invisible_Click"/>
                <ribbon:RibbonButton x:Name="Help2"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Help" />
                <ribbon:RibbonButton x:Name="Quit2"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Quit" Click="Quit_Click" />
            </ribbon:RibbonGroup>

        </ribbon:RibbonTab>
        <ribbon:RibbonTab x:Name="SettingsTab" 
                          Header="Settings">
            <ribbon:RibbonGroup x:Name="Group21" 
                                Header="">
                <ribbon:RibbonButton x:Name="Update3"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Update" />

                <ribbon:RibbonButton x:Name="Register3"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Register" />
                <ribbon:RibbonButton x:Name="Uninstall3"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Uninstall" />
                <ribbon:RibbonButton x:Name="Invisible3"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Go invisible" Click="Invisible_Click" />
                <ribbon:RibbonButton x:Name="Help3"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Help" />
                <ribbon:RibbonButton x:Name="Quit3"
                                     LargeImageSource="/T-Spy;component/Resources/favicon.ico"
                                     Label="Quit"  Click="Quit_Click"/>
            </ribbon:RibbonGroup>

        </ribbon:RibbonTab>

1 个答案:

答案 0 :(得分:0)

为什么不创建基本类型为功能区:RibbonGroup 的UserControl,然后根据需要将其放入每个部分?然后,您拥有每个控件的唯一上下文,因此没有冲突。

任何属性操作都需要使用依赖属性进行管理。