Validating / Styling

2 posts, 0 answers
  1. Martin Egger
    Martin Egger avatar
    6 posts
    Member since:
    Mar 2010

    Posted 30 Apr 2010 Link to this post

    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

    <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<stringstring> m_validationErrors = new Dictionary<stringstring>(); 
     
            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.






  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 06 May 2010 Link to this post

    Hello Martin Egger,

    We are unable to run your project because there are missing parts.
    Could you send us sample project (you have to open a support ticket in order to attach files) so that we can be sure that we are working on the same issue?

    Kind regards,
    Hristo
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top