This is a migrated thread and some comments may be shown as answers.

Canceling state change

3 Answers 63 Views
ImageButton
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kristian
Top achievements
Rank 1
Kristian asked on 30 Jul 2013, 06:57 AM
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.

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 02 Aug 2013, 08:50 AM
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.
0
Kristian
Top achievements
Rank 1
answered on 03 Aug 2013, 05:56 PM
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.
0
Todor
Telerik team
answered on 08 Aug 2013, 06:27 AM
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.
Tags
ImageButton
Asked by
Kristian
Top achievements
Rank 1
Answers by
Todor
Telerik team
Kristian
Top achievements
Rank 1
Share this question
or