Posted 14 years ago by Ray Huger
Version: 10.1.0523
Avatar
I want the text in the popup button to reflect the font editing I'm enabling when I open the popup. So I need TextDecoration. How do I get at the text of the button face to underline it?

Comments (4)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ray,

You would need to use a custom DataTemplate and assign it to the PopupButton.ContentTemplate. In your DataTemplate you'd include a TextBlock with the TextDecorations set appropriately, and Text bound to the current context (i.e. "{Binding}").


Actipro Software Support

Posted 14 years ago by Ray Huger
Avatar
Good. The Text does come through with {Binding}. How do I bind the DataTrigger to actually do the Underline. The following shows the title in the textblock and the binding for FontWeight works, but inside the ContentTemplate the IsUnderlined binding does not work.


<DataTemplate x:Key="fontItemsTemplate">
<shared:PopupButton
FontWeight="{Binding Weight}"
Content="{Binding Title}">
<shared:PopupButton.ContentTemplate>
<DataTemplate>
<TextBlock x:Name="title" Text="{Binding}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsUnderlined}" Value="True">
<Setter TargetName="title" Property="TextDecorations" Value="Underline" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</shared:PopupButton.ContentTemplate>
</shared:PopupButton>
</DataTemplate>

[Modified at 06/29/2010 02:27 PM]
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Ray,

Your inner DataTemplate only has access to the "content" you pass down, which is Title. So you can't bind to IsUnderlined, because the DataContext is a string, not your custom object. You can either pass the custom object down like below, or use a RelativeSource to find the parent PopupButton then access it's DataContext.IsUnderlined.
<DataTemplate x:Key="fontItemsTemplate">
    <shared:PopupButton FontWeight="{Binding Weight}" Content="{Binding}">
        <shared:PopupButton.ContentTemplate>
            <DataTemplate>
                <TextBlock x:Name="title" Text="{Binding Title}" />
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Path=IsUnderlined}" Value="True">
                        <Setter TargetName="title" Property="TextDecorations" Value="Underline" />
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </shared:PopupButton.ContentTemplate>
    </shared:PopupButton>
</DataTemplate>


Actipro Software Support

Posted 14 years ago by Ray Huger
Avatar
That works perfectly. I now realize that I was asking a WPF binding question and the PopupButton is just following the rules of a well behaved control.
The latest build of this product (v24.1.1) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.