I'm creating a custom control class inherited from the ContentControl.
[TemplatePart(Name = PagingBase.NavigationBarTopPanelName, Type = typeof(StackPanel))]
[TemplatePart(Name = PagingBase.NavigationBarBottomPanelName, Type = typeof(StackPanel))]
public class PagingBase: ContentControl
{
...
...
}
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?
"If I've answered your query, please mark "Answered".