Posts Tagged cancel
How do I cancel a databinding property set in WPF?
Posted by Brian Seekford in WPF on November 30, 2011
I have a combobox in WPF that I am using the SelectedItem property with a DataBinding and sometimes certain items shouldn’t be selected based on certain criteria. Mine was that two comboboxes couldn’t have the same value.
Yes, there are other ways, such as removing invalid values from other boxes, but here was my solution for preventing the invalid property set by cancelling the selection/property set.
WPF sucks in this manner as there isn’t an easy way to update it. You can’t raise the property updated event since the binding ignores those when setting, to avoid recursion issue I suppose. (Yes, developers could defend by not raising the events if the property doesn’t change)
Anyway, the solution is simply to raise the property changed after the operation, by simply posting it to the work queue on the UI thread right afterward.
Code: in C#
public MyHeaderType SelectedHeader
{
get { return this.selectedHeader; }
set
{
bool resetMe= validateValue(value);
var origVal = selectedHeader;//store for reset
selectedHeader = value;
RaisePropertyChanged(() => SelectedHeader);
if (resetMe)//Why do I need to set the value above? No idea. Doesn’t work unless I do it that way. Yes. I tried.
{
Application.Current.Dispatcher.BeginInvoke( //force a reenter to put it back……
new Action(() =>
{
SelectedHeader = origVal;//put me back to the correct value.
}),
DispatcherPriority.ContextIdle,
null
);
}
}
}
Happy Coding!
Best Buy cancels every StarCraft II Pre-Order
Posted by Brian Seekford in Rants on July 7, 2010
Best Buy in their infinite stupidity decided to cancel every order for StarCraft II. Why? Well, if you are expecting a good reason, it’s not coming.
They found that their was a glitch on their site and some people were able to order the game for $5.99 instead of $59.99. I ordered it as the proper price, and so did a lot of other people.
How did Best Buy decided to handle the issue? Cancel just the errant orders you say? Of course not. Some retard made the decision to cancel them all. Every order. Over 9,000+ orders maybe even a lot more.
It’s a big company, so the decision maker is probably going to keep his job despite causing the company to lose half a million in revenue on top of the customer frustration, call center costs, and general ill will.
Good Job Best Buy! Way to go, brilliant management.
Excuse the rant, they just really pi$$ed me off.