Canceling state change

4 posts, 0 answers
  1. Kristian
    Kristian avatar
    4 posts
    Member since:
    Feb 2013

    Posted 30 Jul 2013 Link to this post

    What would be the best way to cancel the button state change?
    I use the IsChecked property which is bound to my viewmodel property. I have tried to skip the change of viewmodel property in its setter but the button image still changes.
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 02 Aug 2013 Link to this post

    Hello Kristian,

    Thank you for writing.

    If I understand correctly your scenario then this is not possible. When RadImageButton's IsChecked is true, the button is supposed to seem pressed. If you want to have the IsChecked property bound to the property of your View Model but depending on some circumstances not take the value, you can use a converter along with the binding. If you want IsChecked to be true, but the button to seem like it's not pressed, please share some more details about the scenario so that we can try to find a workaround for you.

    Regards,
    Todor
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
  3. DevCraft banner
  4. Kristian
    Kristian avatar
    4 posts
    Member since:
    Feb 2013

    Posted 03 Aug 2013 Link to this post

    Thanks for your reply.
    My scenario is the following:
    I have a button which represents a bookmark button, when presed the item is added to bookmarks.
    In my view model I have a property IsBookmarked with the following setter:
    set
                {
                    bool success = true;
                    if (value)
                    {
                        success = DataAccess.AddToFavorites(this._event);
                    }
                    else DataAcces.RemoveFromFavorites(this._event);
     
                    if (success == false) _IsBookmarked = false;
                    else _IsBookmarked = value;
                    OnPropertyChanged("IsBookmarked");
     
                }

    In the method AddToFavorites I check if more than 100 bookmarks are added, if yes then this item is not bookmarked and the return value is false.
    The IsBookmarked property is TwoWay bound to the IsChecked property of the ImageButton. When I set the property to false in the setter, the image of the button still changes like its set to true.
    I have tried using a converter which always returned false (for testing) in both Convert, and ConvertBack methods, but after the button is pressed the Image still changed, and this is my problem. I need something like a Checking event, in which I can call e.Cancel = true.
  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 08 Aug 2013 Link to this post

    Hello Kristian,

    RadImageButton (in its ToggleButton state) aims is to provide an experience similar to the one of the native ToggleButton. From what I see, your scenario wouldn't be possible with the native control as well. If I understand correctly, you want to have a button which does nothing when it's pressed, but from a user's perspective such an irresponsive behavior would seem as if something is wrong with this button. The more common approach would be to add another property. Something like IsBookmarkingEnabled and have it bound to the button's IsEnabled property. This way when you already have 100 bookmarked items, the button can be disabled (or if you prefer, you can set its Visibility to Collapsed) and the users will not be able to press it. This way they will be aware that they can't add the current item as a favorite.

    Regards,
    Todor
    Telerik
    Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Back to Top
DevCraft banner