简体   繁体   中英

add label to ribbon button with control template

I have created a ControlTemplate for a Ribbon button shown at the end of this post.

It displays fine however I would it to have a label like a standard button. When I add a button using my control template and add Label="blah" nothing is shown - do I need edit my control template?

Also is there a way to change the size the ribbon button takes up on the ribbon as its coming out a bit small?

standard button

<RibbonButton Label="Recalculate Values" 
                              Command="{Binding CommandButtCalcHlds}" 
                              IsEnabled="{Binding ButtHome}"
                              LargeImageSource="MyPath\Calculate1.jpg"/>

button with my control template

<RibbonButton Command="{Binding CommandButtHldChk}" 
                              IsEnabled="{Binding ButtExportToExcel}"
                              Template="{StaticResource buttRibbonCheck}"/>

My control template

<ControlTemplate x:Key="buttRibbonCheck" TargetType="{x:Type RibbonButton}">
        <Grid Height="60" Width="60">
            <Ellipse Name="outerCircle" >
                <Ellipse.Fill>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0" Color="Blue"/>
                        <GradientStop Offset="1" Color="Red"/>
                    </LinearGradientBrush>
                </Ellipse.Fill>
            </Ellipse>
            <Ellipse Margin="5">
                <Ellipse.Fill>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Offset="0" Color="White"/>
                        <GradientStop Offset="1" Color="Transparent"/>
                    </LinearGradientBrush>
                </Ellipse.Fill>
            </Ellipse>
            <TextBlock Text="Check" FontWeight="Bold" FontSize="18" Padding="2" LineHeight="20" 
                       HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Black"/>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="outerCircle" Property="Fill" Value="Purple"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="RenderTransform">
                    <Setter.Value>
                        <ScaleTransform ScaleX=".9" ScaleY=".9"/>
                    </Setter.Value>
                </Setter>
                <Setter Property="RenderTransformOrigin" Value=".5,.5"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

set margin of the Ribbon button

<RibbonTab Header="Insert">

                    <RibbonButton Command="{Binding CommandButtHldChk}" VerticalAlignment="Top" Margin="0,-50,0,0"
                              IsEnabled="{Binding ButtExportToExcel}"
                              Template="{StaticResource buttRibbonCheck}" />
</RibbonTab>

or use

<RibbonGroup>
                    <RibbonButton Command="{Binding CommandButtHldChk}" 
                              IsEnabled="{Binding ButtExportToExcel}"
                              Template="{StaticResource buttRibbonCheck}"/>
</RibbonGroup >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM