简体   繁体   中英

Hold state of buttons dont work after binding

I have a UWP application where the buttons hold state work just fine until I bind (any) buttons visibility or editable state where the hold state goes away. The buttons only work if I tap super quickly after something gets binded. If I switch to a different view then back to the original view, the buttons magically work again. Anyone have any ideas what could be causing this?

Added the IsHoldingState="true" to parent and button in xaml.

xaml code

<controls:RoundedButton Grid.Row="2" Style="{StaticResource SubmitButtonStyle}" Command="{Binding SubmitCommand}" VerticalAlignment="Bottom" Visibility="{Binding IsNotEmpty, Converter={StaticResource visibilityConverter}, ConverterParameter=false}" Margin="-16,-16,-32,-32" Width="384" Height="112" Opacity="0" Background="Transparent" />


<controls:RoundedButton Grid.Row="2" Style="{StaticResource SubmitButtonStyle}" Command="{Binding SubmitCommand}" VerticalAlignment="Bottom" Visibility="{Binding IsNotEmpty, Converter={StaticResource visibilityConverter}, ConverterParameter=false}">

cs code (where the binding is updated via onpropertychanged)

                      private bool isNotEmpty;
    public bool IsNotEmpty
    {
        get { return isNotEmpty; }
        set { Set(() => IsNotEmpty, ref isNotEmpty, value); }
    }

        protected bool Set<T>(Expression<Func<T>> selectorExpression, ref T field, T value)
    {
        if (EqualityComparer<T>.Default.Equals(field, value)) return false;
        field = value;
        RaisePropertyChanged(selectorExpression);
        return true;
    }


        protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> selectorExpression)
    {
        var propertyName = GetPropertyName(selectorExpression);
        OnPropertyChanged(propertyName);
    }


  protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

The problem may be in your ConverterParameter , ConverterParameter can't be directly assigned to a boolean value, please try this:

<Page.Resources>
    <x:Boolean x:Key="DefaultParameter">False</x:Boolean>
</Page.Resources>
...
<controls:RoundedButton Visibility="{Binding IsNotEmpty, Converter={StaticResource visibilityConverter}, ConverterParameter={StaticResource DefaultParameter}}">

Best regards.

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