0

Due to some complicated UI requirements, we are using Frame with Tap Gesture as a replacement of Button. Is it possible to add Visual States("Focused", "Clicked", "Disabled") for a normal view?

Chris Tina
  • 55
  • 6
  • Does this answer your question? [How to add a custom button state](https://stackoverflow.com/questions/4336060/how-to-add-a-custom-button-state) – Marcos Vasconcelos Feb 03 '20 at 14:01
  • Hi , I think Frame is well for this , could you share more info not using Frame to implement it . – Junior Jiang Feb 04 '20 at 05:32
  • I need to add custom states for a view(frame), not button, in Xamarin forms. Any suggestions for it? – Chris Tina Feb 04 '20 at 05:58
  • @ChrisTina You can use [Bindable Properties](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/xaml/bindable-properties#create-a-property) to create custom property for Frame . – Junior Jiang Feb 04 '20 at 06:54

1 Answers1

1

You can create a custom Frame to add custom bindable properties to implement it .For example , add three properties for CustomFrame . You can add other more custom property by what needed.

public class CustomFrame :Frame
{
    public static readonly BindableProperty CustomFocusedProperty = BindableProperty.Create("CustomFocused", typeof(bool), typeof(CustomFrame), null);

    public bool CustomFocused
    {
        get { return (bool)GetValue(CustomFocusedProperty); }
        set { SetValue(CustomFocusedProperty, value); }
    }


    public static readonly BindableProperty CustomClickedProperty = BindableProperty.Create("CustomClicked", typeof(bool), typeof(CustomFrame), null);

    public bool CustomClicked
    {
        get { return (bool)GetValue(CustomClickedProperty); }
        set { SetValue(CustomClickedProperty, value); }
    }


    public static readonly BindableProperty CustomDisabledProperty = BindableProperty.Create("DisabledFocused", typeof(bool), typeof(CustomFrame), null);

    public bool DisabledFocused
    {
        get { return (bool)GetValue(CustomDisabledProperty); }
        set { SetValue(CustomDisabledProperty, value); }
    }
}

Uesd in Xaml : <local:CustomFrame x:Name="CustomFrame" />

Then you can set or get vaule from custom property :

CustomFrame.CustomClicked = true;
CustomFrame.CustomFocused = true;
CustomFrame.CustomDisabled = true;
Junior Jiang
  • 10,415
  • 1
  • 5
  • 21