ApplicationButton with ControlTemplate

Ribbon for WPF Forum

Posted 14 years ago by Jim Strav
Version: 10.1.0520
Avatar
I want to completely replace the ApplicationButton but keep it's functionality. When I use a ControlTemplate with a vector graphic in it, the ApplicationButton does not work anymore.

Here is the XAML. I do not get the click event in code behind nor does it pop up an ApplicationMenu (not shown here). The ApplicationMenu I am using does work when I remove the ControlTemplate.

        <ribbon:ApplicationButton x:Name="AppButton" 
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Top"                                  
                                  Click="AppButton_Click_3">
            <ribbon:ApplicationButton.Template>
                <ControlTemplate TargetType="Button">
                    <Path Data="M0,0 L18,24 36,0z" Stroke="Black" Fill="Black" />
                </ControlTemplate>
            </ribbon:ApplicationButton.Template>
        </ribbon:ApplicationButton>
So this works for a regular button (I get the click event in code behind):

<Button x:Name="AppButton" 
    HorizontalAlignment="Left"
    VerticalAlignment="Top"                                  
    Click="AppButton_Click_1">
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Path Data="M0,0 L18,24 36,0z" Stroke="Black" Fill="Black" />
        </ControlTemplate>
    </Button.Template>
</Button>
FYI...
I also tried using a regular shared:PopupButton which does work with a ControlTemplate, but then the ApplicationMenu doesn't behavior correctly. For example, once you hover over a ribbon:SplitButton (like Save As), you then have to explicitly click back on a different menu to get back to the Recent Documents. Normally, just hovering back over something else returned you to Recent Documents.

Comments (1)

Posted 14 years ago by Jim Strav
Avatar
I found a workaround. I am using a ToggleButton to trigger the ApplicationButton's IsPopupOpen property. The ToggleButton uses the ControlTemplate to show my graphic and I sized the ApplicationButton to 1x1 pixels and hid it behind the ToggleButton.

By the way, I am not using the Ribbon bar, just elements from the ribbon namespace. In this case, a stand-alone ApplicationButton that hosts my application's Office-like menu.
The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.