This is a migrated thread and some comments may be shown as answers.

Do I have to wrapping something with <AdornerDecorator>?

4 Answers 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Trump
Top achievements
Rank 1
Trump asked on 31 May 2018, 12:41 AM

I have a customized cell template.

<telerik:GridViewDataColumn Header="Contact" DataMemberBinding="{Binding CustAccountsLocationContact.FirstName}">
    <telerik:GridViewDataColumn.CellTemplate>
         <DataTemplate>
               <TextBox Text="{Binding SomeText, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
         </DataTemplate>
   </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

 

Now in Model class SomeText property there is a [required] attribute. Similar this, I created the error template as

<ControlTemplate x:Key="errorTemplate">
    <DockPanel>
        <Border BorderBrush="Red" BorderThickness="1">
            <AdornedElementPlaceholder x:Name="controlWithError"/>
        </Border>
        <TextBlock Foreground="Red" FontSize="20" FontFamily="Segoe UI" Margin="3,0,0,0"  MouseDown="Exclamation_MouseDown"  Tag="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=controlWithError}">!</TextBlock>
    </DockPanel>
</ControlTemplate>

 

However I can not see the error template if validation failed. By the answer on stackoverflow, it seems need  to wrap some template with <AdornerDecorator>

Is it the solution to my case? If so, how to wrap it around telerik control?

Thank you.

4 Answers, 1 is accepted

Sort by
0
Trump
Top achievements
Rank 1
answered on 07 Jun 2018, 12:20 PM
Any help?
0
Martin
Telerik team
answered on 12 Jun 2018, 09:02 AM
Hello, 

May I ask you what is your exact requirment and why you want to create a custom validation? I ask you because RadGridView provides the data validation which feature enables you to take complete control of the entered data. You can take a look at our Validating Data Through Data Annotations article where you can find how to achieve the similar behavior.


Regards,
Martin Vatev
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Trump
Top achievements
Rank 1
answered on 30 Aug 2018, 12:35 AM

Found the solution. I have to put the textbox in the StackPanel. Not sure why, but it works.

<telerik:GridViewDataColumn Header="Contact" DataMemberBinding="{Binding CustAccountsLocationContact.FirstName}">
    <telerik:GridViewDataColumn.CellTemplate>
         <DataTemplate>
             <StackPanel>
               <TextBox Text="{Binding SomeText, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
             </StackPanel>
         </DataTemplate>
   </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
0
Martin
Telerik team
answered on 03 Sep 2018, 08:29 AM
Hello,

Thank you for sharing the workaround of the desired behavior the community. But keep in mind that for a scenario where the data should be validated, RadGridView provides its own data validation mechanism. 

Regards,
Martin Vatev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Trump
Top achievements
Rank 1
Answers by
Trump
Top achievements
Rank 1
Martin
Telerik team
Share this question
or