Hi
I have a small problem. When I validate a TextBoxes Value and than giving the User a visual feedback everything works prefectly fine.
When I do this with a RadComboBox, the only thing that works is the validation part. But I don't get any visual feedback. Here is the XAML part in my App.xaml
And here the the C# Part for Validation. Allthough I am convincied that the validation works. Tested it several times.
Thanks for your help.
I have a small problem. When I validate a TextBoxes Value and than giving the User a visual feedback everything works prefectly fine.
When I do this with a RadComboBox, the only thing that works is the validation part. But I don't get any visual feedback. Here is the XAML part in my App.xaml
<Application x:Class="CDM.App" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" |
xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" |
> |
<Application.Resources> |
<Storyboard x:Key="FlashError"> |
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" |
Storyboard.TargetProperty="(UIElement.Visibility)"> |
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/> |
<DiscreteObjectKeyFrame KeyTime="00:00:05" Value="{x:Static Visibility.Hidden}"/> |
</ObjectAnimationUsingKeyFrames> |
</Storyboard> |
<Style x:Key="myErrorTemplate" TargetType="Control"> |
<Setter Property="Validation.ErrorTemplate"> |
<Setter.Value> |
<ControlTemplate> |
<StackPanel Orientation="Vertical"> |
<Border BorderBrush="Red" BorderThickness="1"> |
<AdornedElementPlaceholder Name="mycontrol"> |
<Label Foreground="White" Background="Red" |
Content="{Binding ElementName=mycontrol, |
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"> |
<Label.Triggers> |
<EventTrigger RoutedEvent="FrameworkElement.Loaded"> |
<BeginStoryboard Storyboard="{StaticResource FlashError}" /> |
</EventTrigger> |
</Label.Triggers> |
</Label> |
</AdornedElementPlaceholder> |
</Border> |
<!--<Label Foreground="White" Background="Red" |
Content="{Binding ElementName=mycontrol, |
Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"> |
</Label>--> |
</StackPanel> |
</ControlTemplate> |
</Setter.Value> |
</Setter> |
<Style.Triggers> |
<Trigger Property="Validation.HasError" Value="true"> |
<Setter Property="ToolTip" |
Value="{Binding |
RelativeSource={x:Static RelativeSource.Self}, |
Path=(Validation.Errors)[0].ErrorContent}" /> |
</Trigger> |
</Style.Triggers> |
</Style> |
<Style TargetType="TextBox" BasedOn="{StaticResource myErrorTemplate}" /> |
<Style TargetType="CheckBox" BasedOn="{StaticResource myErrorTemplate}" /> |
<Style TargetType="telerik:RadComboBox" BasedOn="{StaticResource myErrorTemplate}" /> |
</Application.Resources> |
</Application> |
And here the the C# Part for Validation. Allthough I am convincied that the validation works. Tested it several times.
public Platten() |
{ |
this.preisReference.AssociationChanged += new CollectionChangeEventHandler(preisReference_AssociationChanged); |
this.AddError("preis", "Preiscode fehlt!"); |
} |
void preisReference_AssociationChanged(object sender, CollectionChangeEventArgs e) |
{ |
if (e.Action == CollectionChangeAction.Remove) |
{ |
OnPropertyChanging("preis"); |
} |
else |
{ |
if (e.Action == CollectionChangeAction.Add) |
{ |
this.RemoveError("preis"); |
} |
OnPropertyChanged("preis"); |
} |
} |
#region IDataErrorInfo Members |
private Dictionary<string, string> m_validationErrors = new Dictionary<string, string>(); |
private void AddError(string columnName, string msg) |
{ |
if (!m_validationErrors.ContainsKey(columnName)) |
{ |
m_validationErrors.Add(columnName, msg); |
} |
} |
private void RemoveError(string columnName) |
{ |
if (m_validationErrors.ContainsKey(columnName)) |
{ |
m_validationErrors.Remove(columnName); |
} |
} |
public bool HasErrors |
{ |
get { return m_validationErrors.Count > 0; } |
} |
public string Error |
{ |
get |
{ |
if (m_validationErrors.Count > 0) |
{ |
return "Customer data is invalid"; |
} |
else |
{ |
return null; |
} |
} |
} |
public string this[string columnName] |
{ |
get |
{ |
if (m_validationErrors.ContainsKey(columnName)) |
{ |
return m_validationErrors[columnName]; |
} |
else return null; |
} |
} |
#endregion |
Thanks for your help.