Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Custom Control, Initialization Order?
5 replies. Latest Post by Dave Relyea on October 11, 2008.
(0)
codebased
Participant
806 points
360 Posts
10-06-2008 8:41 PM |
[TemplatePart(Name = PagingBase.NavigationBarTopPanelName, Type = typeof(StackPanel))] [TemplatePart(Name = PagingBase.NavigationBarBottomPanelName, Type = typeof(StackPanel))] public class PagingBase: ContentControl { ... ... }
[TemplatePart(Name = PagingBase.NavigationBarTopPanelName, Type = typeof(StackPanel))] [TemplatePart(Name = PagingBase.NavigationBarBottomPanelName, Type = typeof(StackPanel))]
The template is as follow:<Style TargetType="local:PagingBase"> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFFFFCF4" Offset="0"/> <GradientStop Color="#FFDAD8C9" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="Foreground" Value="#FF000000"/> <Setter Property="BorderThickness" Value="2,0,2,2"/> <Setter Property="BorderBrush" Value="#FF2366C6"/> <Setter Property="OpaqueColor" Value="#44FFFFFF"/> <Setter Property="NavigationBarBackground"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFA9CCFF" Offset="0.00" /> <GradientStop Color="#FF8EBBFC" Offset="0.28" /> <GradientStop Color="#FF68A3F8" Offset="0.32" /> <GradientStop Color="#FF458DF5" Offset="0.90" /> <GradientStop Color="#FF2366C6" Offset="1.00" /> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="NavigationBarForeground" Value="#FFFFFFFF" /> <Setter Property="Padding" Value="10"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:PagingBase"> <Grid x:Name="GridRoot" Background="{TemplateBinding OpaqueColor}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition Height="*"/> <RowDefinition Height="30"/> </Grid.RowDefinitions> <!-- Top Navigation Bar --> <StackPanel Grid.Row="0" Orientation="Horizontal" x:Name="NavigationBarTopPanel" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" /> <!-- Content presenter--> <ContentPresenter Grid.Row="1" x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/> <!-- Bottom Navigation Bar --> <StackPanel Grid.Row="2" Orientation="Horizontal" x:Name="NavigationBarBottomPanel" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" /> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
The way I am using in the User Control is: <self:PagingBase x:Name="EmployeeListPage" TotalRecords="100" PageSize="5" OnPageChanged="EmployeeList_OnPageChanged" Orientation="Both" >...</...>
<
I'm expecting two controls to be accessible before the value is being set through Orientation property however, they are not avaiable when the object is constructed and I can only access this once OnApplyTemplate is being called.
I'm setting the default style key = typeof(PagingBase) in the constructor of this control.
Any idea how the initialisation order work for the custom controls?
Yi-Lun L...
All-Star
25052 points
2,747 Posts
10-08-2008 6:05 AM |
Hello, can you be more specific on your requirement? Do you want to access EmployeeListPage.Orientation in the UserControl's constructor? That will not work. You need to call EmployeeListPage.ApplyTemplate to force the template to be applied.
10-08-2008 6:28 PM |
I did the same and it works. Thanks a ton.
coughlinj
Member
334 points
114 Posts
10-08-2008 8:23 PM |
I'm constantly questioning myself as to when the ApplyTemplate is called in the lifecycle. I have even noticed and have been shocked that it can be called multiple times... usually when this happens its because I've updated the ContentTemplate or something (sorry don't remember the extact instance).
Anyways I'm not sure if this was the original question but I would like to see a writeup on the LifeCycle of a Custom Control. The key items I'm looking for are when are the following called and in what order...
OnApplyTemplate,
Measure
Arrange
R3al1ty
185 points
72 Posts
10-08-2008 10:31 PM |
I second this, can someone blog about this topic?
Dave Relyea
1084 points
249 Posts
10-11-2008 1:29 PM |
http://blogs.msdn.com/devdave/archive/2008/10/11/control-lifecycle.aspx
Hope that helps a bit. If there are other things you'd like to see in the table, please let me know.