This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi I am using a CurrencyTextBox control. The problem that I am having is that I do not see a TextChanged event. I would like to be able to do a validation on the data being entered. I tried using "TextUpdated" but that does not work.
<ms:CurrencyTextBox Grid.Column="1" Grid.Row="8" Name="mTxtSellPrice" What event should I use for Text being changed or is there an example that I can look at. Thanks
|
|
|
Hi I am using a CurrencyTextBox control. The problem that I
am having is that I do not see a TextChanged event. I would like to be
able to do a validation on the data being entered. I tried using
"TextUpdated" but that does not work. <ms:CurrencyTextBox Grid.Column="1" Grid.Row="8" Name="mTxtSellPrice" Here I am using a standard TextBox to handle validation and using a TextChanged how can I do this with a CurrencyTextBox and also handle validation. <TextBox Style="{StaticResource textBoxInError}" Grid.Column="1" Grid.ColumnSpan="1" Grid.Row="7" VerticalAlignment="Center" Name="mTxtQuantity" Margin="3" TextChanged="mTxtQuantity_TextChanged" TabIndex="6">
What event should I use for Text being changed and is there an example that I can look at. |
|
|
You can catch the bubbling TextBox.TextChanged event from the contained TextBox: <ms:CurrencyTextBox Value="123" TextBoxBase.TextChanged="CurrencyTextBox_TextChanged" /> You should be able to data bind (including validations) the Text property in the same way as for a TextBox but you might want to consider binding the Value property rather than the Text property. |
|
|
Great ! Thanks I will give this a try.
|
|
|
Hi Ivan, Is it possible to provide an example on using the validation from my example. I am not having any luck getting this to work.
|
|
|
Sure. First, let's create a simple business object. You've obviously already got one of these, but I wanted to write my demo example out so as to make sure we're both on the same page. public class Sprocket : INotifyPropertyChanged, IDataErrorInfo A fair chunk of this is INotifyPropertyChanged boilerplate. The IDataErrorInfo implementation is barbarous but it will do for demo purposes. We set the window data context to a Sprocket instance: DataContext = new Sprocket { Price = 246 }; Now let's create a validation rule, say a range constraint: public class RangeRule : ValidationRule Again, you've clearly already got one of these. Finally, we create a CurrencyTextBox and hook up its TextBoxBase.TextChanged event and bind its Value with validation. This is similar to your example except that I am binding the Value property rather than the Text property, since Value is more appropriate to a numeric data property like Price or Quantity: <ms:CurrencyTextBox TextBoxBase.TextChanged="CurrencyTextBox_TextChanged"> Now when I type into the CurrencyTextBox, I see the TextChanged handler running (printing output to the debug window in my case). Also, if I type a value greater than 500, the CurrencyTextBox gets a red border. (If I remove the ValidatesOnDataErrors setting and type a value greater than 1000, the CurrencyTextBox gets a red border, so I know the RangeRule is being applied as well as IDataErrorInfo.) Hope this helps! |
|
|
Thanks Ivan, Good example ! |
|
|
Hi Ivan, I was able to get the example that you sent to work. My only problem now is how can I get the DropDownDatePicker to remove the calendar and just show the date selected after loosing focus without having the user click on the arrow.
|
|
|
Hmm, this feels like a bit of a bug. However, you can work around it as follows: 1. Add a PreviewKeyDown handler to the control, and set its KeyboardNavigation.TabNavigation attached property to None: <ms:DropDownDatePicker KeyboardNavigation.TabNavigation="None" PreviewKeyDown="DropDownDatePicker_PreviewKeyDown" /> 2. In the PreviewKeyDown handler, close the drop-down and handle the tabbing manually: private void DropDownDatePicker_PreviewKeyDown(object sender, KeyEventArgs e) 3. The implementation of FindChild looks like this: private static T FindChild<T>(DependencyObject startingFrom) I know this is ugly but hopefully it will be okay until we are able to improve the built-in tab handling. |
|