Can I change RadPathButton's ContentVisibility VisualState?

1 Answer 22 Views
Buttons
Joe
Top achievements
Rank 1
Iron
Veteran
Iron
Joe asked on 03 Jan 2022, 11:54 PM | edited on 03 Jan 2022, 11:55 PM
Is there a way to control the visibility of the Content of a RadPathButton via some property?  From the documentation it seems not but the ControlTemplate makes it appear otherwise.

Background: I was looking into making a RadPathButton that would hide its content (and only show the PathGeometry) when it got small enough.  My idea was either to derive a class from this or to create a WPF Behavior that added a ContentVisibility  DependencyProperty to take care of this for me.  Then I would write my own style with my own ControlTemplate to honor this property

But when I looked at Telerik's ControlTemplate for RadPathButton (in the Windows8Touch theme) I saw a  reference to "ContentVisibilityStates" group in the VisualStateManager section that looked like what I need.  It has a Visible and Collapsed states.  If I could find a way to make the control enter the Collapsed state, it would collapse the content exactly as I desire.

However I cannot see any sort of property that binds to this.  So how is it changed?  Is it possible for me to bind some property to the button to make its content disappear when I need it to?
<VisualStateGroup x:Name="ContentVisibilityStates">
    <VisualState x:Name="Visible" />
    <VisualState x:Name="Collapsed">
        <Storyboard>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentHost"
                Storyboard.TargetProperty="Visibility">
                <DiscreteObjectKeyFrame KeyTime="0">
                    <DiscreteObjectKeyFrame.Value>
                        <Visibility>Collapsed</Visibility>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </VisualState>
</VisualStateGroup>

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 06 Jan 2022, 06:03 PM

Hello Joe,

The easiest approach for achieving the wanted result would be to set an element, for example, TextBlock, inside the Content property, and bind its Visibility property to the property of the view model. Then, you could create a converter to convert the bool value to a Visibility value. It is important that, if the view model property is True, the returned value to be Visibility.Hidden.

The following code snippets show this approach:

<Window.Resources>
    <local:MyBooleanToVisibilityConverter x:Key="MyBooleanToVisibilityConverter"/>
</Window.Resources>
<Grid>
	<telerik:RadPathButton>
		<telerik:RadPathButton.Content>
			<TextBlock Text="Path Button" Visibility="{Binding MyVisibilityProperty, Mode=TwoWay, Converter={StaticResource MyBooleanToVisibilityConverter}}" />
		</telerik:RadPathButton.Content>
	</telerik:RadPathButton>
</Grid>	
The MyBooleanToVisibilityConverter implementation is as follows:
public class MyBooleanToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if ((bool)value)
        {
            return Visibility.Hidden;
        }

        return Visibility.Visible;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

This produces the following result:

With that said, could you give this approach a try?

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Buttons
Asked by
Joe
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Stenly
Telerik team
Share this question
or