Using a Control Template for all controls across the application
Posted
by samar
on Stack Overflow
See other posts from Stack Overflow
or by samar
Published on 2010-04-19T07:59:07Z
Indexed on
2010/04/19
8:03 UTC
Read the original article
Hit count: 286
wpf-controls
Hi,
I have a control template in one of my pages and i am assigning this template to my textbox's Validation.ErrorTemplate property. The following code would give you a better view.
<ControlTemplate x:Key="ValidationErrorTemplate"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <AdornedElementPlaceholder/> <Image Name="ValidizorImage" Stretch="None" Source="validizor.gif" ToolTip="{Binding [0].ErrorContent}" ToolTipService.InitialShowDelay="0" ToolTipService.ShowDuration="60000"/> </StackPanel> </ControlTemplate>
The above template sets the image at the end of the textbox which is having the error. This template is used as below.
<TextBox Grid.Column="5" Grid.Row="1" x:Name="txtemail" Grid.ColumnSpan="3" Margin="0,1,20,1" Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}" />
My question here is
I want to move this control template outside of this page so that i can use it across the application.
I tried putting the exact same code of the control template in a user control say "ErrorUC" and using it as below
TextBox1.SetResourceReference (System.Windows.Controls.Validation.ErrorTemplateProperty, new ErrorUC());
On running the above code i learnt that "AdornedElementPlaceholder" can be used only in templates and not in user controls. If i comment the same i am not getting the desired result.
Can anyone please help! Thanks in advance!
Regards,
Samar
© Stack Overflow or respective owner