I created a WPF (.Net 4) UserControl containing some ComboBoxes and a TextBox. In XAML, some ValidationRules are bound to the TextBox. If the TextBox contains invalid data, a red frame is shown, and the tooltip is set to the error description. Works well.
Next, I placed two instances of that UserControl on a form, and added a button. In XAML, the button is connected to a RelayCommand of the ViewModel. Now I want the button to be enabled only when both of the UserControls contain valid data only.
Not a problem, I thought, let me use a strategy which works elsewhere. I added a trigger:
But there is a catch: Validation.HasError is always false for the UserControls - the Validation failed for an element inside the UserControl, not for the UserControl proper.
I know that I can register the Click event of the button, check the validity there using the method shown in http://stackoverflow.com/questions/127477/detecting-wpf-validation-errors[^], and prevent the execution of the RelayCommand by setting the Handled property of the RoutedEventArgs to true. But that looks more like WTF than WPF.
What do you suggest? How can I retrieve the Validation Errors of the UserControl's children? Or how can I get them in the RelayCommand's CanExecute method? Or some other tricks?
That's not a problem. That's precisely the type of thing a ViewModel is designed to solve. Have a property backing your TextBox of type string, and then test the input there. Only pass the value on if it's an int. Alternatively, back it with a Behavior[^] to ensure the user cannot enter invalid values.
Thanks for the hint. I'll look into that approach.
The vaildation errors occur in the realm of the UserControl, while the Button and its command are in the realm of the Window (and its ViewModel, resp.). Things will become more complicated, but I'll try it.
The user can decide to show Hours, Minutes, or Seconds, or all three.
The content needs to scroll in relation to the scale shown... meaning if Minutes is selected, then every minute the scale needs to move from right to left the "width" of the space of one minute bar. The more ticks shown (seconds), the faster it moves.
The content area needs to be dragable. Once dragging is done, the control should resume responding to timer events.
There has to be a vertical bar that represents "now", and that bar should always be in the center. This should not be an issue since the control is moving in real time, so the center should always be the now position.
There will be dots added to the control in real time that represent event that occurred. Clicking the dot will invoke some other action. (Don't need to code that action right now, just the dots appearing)
I'd like to provide the option for smooth scrolling or incremental scrolling. This would probably be done using a constant motion for smooth scrolling and for incremental, it would move in response to a timer tic.
I have some ideas on how to design this, but I'd like to get some input before I start.
I've looked at this control[^] but it looks overly complex for what I want.
Telerik have a timeline type control but the only time I considered it I found it dramatically over the top with functionality. I would have spent more time customising it to meet my simple needs (chopping bits out) than building a control from scratch. It may be worth looking at for your requirements.
Never underestimate the power of human stupidity