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?
            Asked
            
        
        
            Active
            
        
            Viewed 98 times
        
    0
            
            
        - 
                    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://learn.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 Answers
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
        
- 12,430
 - 1
 - 10
 - 30
 
- 
                    
 - 
                    @ChrisTina OK , if answer be helpful , remember to back and mark it :) – Junior Jiang Feb 05 '20 at 01:08