'宣言 Public Property DialogBoxLauncherTool As ButtonTool
public ButtonTool DialogBoxLauncherTool {get; set;}
DialogBoxLauncherTool プロパティは、キャプション領域内に表示される ButtonTool インスタンスを提供するために使用されます。デフォルトでは、ButtonTool はリソース キーが DialogBoxLauncherToolTemplateKey であるカスタム System.Windows.Controls.ControlTemplate を使用します。このプロパティに設定される ButtonTool インスタンスは、True に設定された添付 IsDialogBoxLauncherToolProperty プロパティを持ち、RibbonGroup の HasDialogBoxLauncherTool は True に設定されます。
Private Sub addRibbonGroup() If xamRibbon.Tabs.Count < 1 Then Return End If Dim igTabItem As RibbonTabItem = xamRibbon.Tabs(0) 'Add RibbonGroup Dim ribbonGroup As New RibbonGroup() ribbonGroup.Caption = "RibbonGroup Members" igTabItem.RibbonGroups.Add(ribbonGroup) 'Add ButtonTool Dim btnToolRemoveFromQAT As ButtonTool = ButtonToolButtonToolButtonTool() btnToolRemoveFromQAT.Caption = "RemoveFromQAT" 'Add ToolTip getRibbonScreenTip(btnToolRemoveFromQAT) End Sub 'Create RibbonScreenTip Private Sub getRibbonScreenTip(ByVal tool As ButtonTool) 'Create XamRibbonScreenTip Dim ribbonScreenTip As New XamRibbonScreenTip() 'XamRibbonScreenTip ribbonScreenTip.Header = "RibbonGroup.DialogBoxLauncherTool" ribbonScreenTip.Footer = "Press F1 for more help." ribbonScreenTip.Content = "The RibbonGroup.DialogBoxLauncherTool property has been set to a ButtonTool. You can right click on this tool to add it to the QAT." If ribbonScreenTip.HasContentImage = False Then ribbonScreenTip.ContentImage = getImageSource("images/icons/Ribbon/xamRibbonDefaultApplicationIcon.png") End If ribbonScreenTip.FooterSeparatorVisibility = Visibility.Visible ribbonScreenTip.HeaderSeparatorVisibility = Visibility.Collapsed 'Create FooterTemplate Dim template As New DataTemplate(GetType(StackPanel)) 'root element Dim elStackPanel As New FrameworkElementFactory(GetType(StackPanel)) Dim mImageSource As ImageSource = getImageSource("images/icons/Ribbon/xamRibbonDefaultApplicationIcon.png") Dim mImage As New Image() mImage.Source = mImageSource Dim bcGround As Brush = Brushes.Bisque elStackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical) elStackPanel.SetValue(StackPanel.BackgroundProperty, bcGround) elStackPanel.SetValue(StackPanel.WidthProperty, System.Convert.ToDouble(200)) elStackPanel.SetValue(StackPanel.HeightProperty, System.Convert.ToDouble(200)) 'create child elements Dim elImage As New FrameworkElementFactory(GetType(Image)) elImage.SetValue(Image.SourceProperty, mImageSource) elImage.SetValue(Image.WidthProperty, System.Convert.ToDouble(150)) elImage.SetValue(Image.HeightProperty, System.Convert.ToDouble(150)) elImage.SetBinding(Image.SourceProperty, New Binding("Source")) Dim elTextBlock As New FrameworkElementFactory(GetType(TextBlock)) elTextBlock.SetValue(TextBlock.TextProperty, "Sample Text") elTextBlock.SetValue(TextBlock.WidthProperty, System.Convert.ToDouble(150)) elTextBlock.SetValue(TextBlock.HeightProperty, System.Convert.ToDouble(150)) 'add child elements elStackPanel.AppendChild(elImage) elStackPanel.AppendChild(elTextBlock) template.VisualTree = elStackPanel 'Create HeaderTemplate Dim template2 As New DataTemplate(GetType(TextBlock)) Dim elTextBlock2 As New FrameworkElementFactory(GetType(TextBlock)) elTextBlock2.SetValue(TextBlock.TextProperty, "Header Text") elTextBlock2.SetValue(TextBlock.WidthProperty, System.Convert.ToDouble(150)) elTextBlock2.SetValue(TextBlock.HeightProperty, System.Convert.ToDouble(100)) template2.VisualTree = elTextBlock2 ribbonScreenTip.FooterTemplate = template ribbonScreenTip.HeaderTemplate = template2 If TypeOf tool Is ButtonTool Then Dim btn As ButtonTool = TryCast(tool, ButtonTool) btn.ToolTip = ribbonScreenTip End If End Sub
private void addRibbonGroup() { if (xamRibbon.Tabs.Count < 1) { return; } RibbonTabItem igTabItem = xamRibbon.Tabs[0]; //Add RibbonGroup RibbonGroup ribbonGroup = new RibbonGroup(); ribbonGroup.Caption = "RibbonGroup Members"; igTabItem.RibbonGroups.Add(ribbonGroup); //Add ButtonTool ButtonTool btnToolRemoveFromQAT = ButtonToolButtonToolButtonTool(); btnToolRemoveFromQAT.Caption = "RemoveFromQAT"; //Add ToolTip getRibbonScreenTip(btnToolRemoveFromQAT); } //Create RibbonScreenTip private void getRibbonScreenTip(ButtonTool tool) { //Create XamRibbonScreenTip XamRibbonScreenTip ribbonScreenTip = new XamRibbonScreenTip(); //XamRibbonScreenTip ribbonScreenTip.Header = "RibbonGroup.DialogBoxLauncherTool"; ribbonScreenTip.Footer = "Press F1 for more help."; ribbonScreenTip.Content = "The RibbonGroup.DialogBoxLauncherTool property has been set to a ButtonTool. You can right click on this tool to add it to the QAT."; if (ribbonScreenTip.HasContentImage == false) { ribbonScreenTip.ContentImage = getImageSource("images/icons/Ribbon/xamRibbonDefaultApplicationIcon.png"); } ribbonScreenTip.FooterSeparatorVisibility = Visibility.Visible; ribbonScreenTip.HeaderSeparatorVisibility = Visibility.Collapsed; //Create FooterTemplate DataTemplate template = new DataTemplate(typeof(StackPanel)); //root element FrameworkElementFactory elStackPanel = new FrameworkElementFactory(typeof(StackPanel)); ImageSource mImageSource = getImageSource("images/icons/Ribbon/xamRibbonDefaultApplicationIcon.png"); Image mImage = new Image(); mImage.Source = mImageSource; Brush bcGround = Brushes.Bisque; elStackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical); elStackPanel.SetValue(StackPanel.BackgroundProperty, bcGround); elStackPanel.SetValue(StackPanel.WidthProperty, System.Convert.ToDouble(200)); elStackPanel.SetValue(StackPanel.HeightProperty, System.Convert.ToDouble(200)); //create child elements FrameworkElementFactory elImage = new FrameworkElementFactory(typeof(Image)); elImage.SetValue(Image.SourceProperty, mImageSource); elImage.SetValue(Image.WidthProperty, System.Convert.ToDouble(150)); elImage.SetValue(Image.HeightProperty, System.Convert.ToDouble(150)); elImage.SetBinding(Image.SourceProperty, new Binding("Source")); FrameworkElementFactory elTextBlock = new FrameworkElementFactory(typeof(TextBlock)); elTextBlock.SetValue(TextBlock.TextProperty, "Sample Text"); elTextBlock.SetValue(TextBlock.WidthProperty, System.Convert.ToDouble(150)); elTextBlock.SetValue(TextBlock.HeightProperty, System.Convert.ToDouble(150)); //add child elements elStackPanel.AppendChild(elImage); elStackPanel.AppendChild(elTextBlock); template.VisualTree = elStackPanel; //Create HeaderTemplate DataTemplate template2 = new DataTemplate(typeof(TextBlock)); FrameworkElementFactory elTextBlock2 = new FrameworkElementFactory(typeof(TextBlock)); elTextBlock2.SetValue(TextBlock.TextProperty, "Header Text"); elTextBlock2.SetValue(TextBlock.WidthProperty, System.Convert.ToDouble(150)); elTextBlock2.SetValue(TextBlock.HeightProperty, System.Convert.ToDouble(100)); template2.VisualTree = elTextBlock2; ribbonScreenTip.FooterTemplate = template; ribbonScreenTip.HeaderTemplate = template2; if (tool is ButtonTool) { ButtonTool btn = tool as ButtonTool; btn.ToolTip = ribbonScreenTip; } }