Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to modify Silverlight template at runtime?
    text
    copied!<p>I have a custom control containing a path that has a templated tooltip. I want to be able to get a reference to a grid in the template at runtime so that I can modify it's children depending on use. </p> <p>I thought I could use GetTemplateChild to get a reference to the grid in the template from within the OnApplyTemplate method of the control but this method is not firing. </p> <pre><code>public override void OnApplyTemplate() { base.OnApplyTemplate(); _tooltipDetails = (Grid)GetTemplateChild("TooltipDetailsGrid"); } </code></pre> <p>How else might I be able to do this?</p> <p>Here is the user control's XAML.</p> <pre><code>&lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="MiX.AssetManagement.UI.Timeline.Silverlight.TimelineBarRibbonItem" FontSize="9.333" Foreground="White" mc:Ignorable="d"&gt; &lt;UserControl.Resources&gt; &lt;ControlTemplate x:Key="ToolTipControlTemplateTimelineView" TargetType="ToolTip"&gt; &lt;StackPanel Orientation="Horizontal" Margin="16,0,0,0"&gt; &lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup x:Name="OpenStates"&gt; &lt;VisualState x:Name="Closed"/&gt; &lt;VisualState x:Name="Open"/&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;Border CornerRadius="4"&gt; &lt;Border.Background&gt; &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#7F000000" Offset="0"/&gt; &lt;GradientStop Color="#B2000000" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Border.Background&gt; &lt;Grid Margin="4"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Border x:Name="Info" Height="16" Width="16" BorderThickness="2" CornerRadius="8" HorizontalAlignment="Left" VerticalAlignment="Top"&gt; &lt;Border.BorderBrush&gt; &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="White" Offset="0"/&gt; &lt;GradientStop Color="#7FFFFFFF" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Border.BorderBrush&gt; &lt;Path Fill="White" Stretch="Fill" Margin="5.229,2.089,5.035,2.82" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" Data="M0.77471197,5.0623446 L2.4198356,5.0623446 L2.4198356,10.18 L0.77471197,10.18 z M0.72914064,3.0891075 L2.4654069,3.0891075 L2.4654069,4.3332038 L0.72914064,4.3332038 z"&gt; &lt;Path.RenderTransform&gt; &lt;TransformGroup&gt; &lt;ScaleTransform/&gt; &lt;SkewTransform/&gt; &lt;RotateTransform/&gt; &lt;TranslateTransform/&gt; &lt;/TransformGroup&gt; &lt;/Path.RenderTransform&gt; &lt;/Path&gt; &lt;/Border&gt; &lt;ContentPresenter d:LayoutOverrides="Width, Height" Margin="20,0,0,0"/&gt; &lt;Grid Grid.Column="1" x:Name="TooltipDetailsGrid"&gt; &lt;TextBlock Text="Tooltip in a Grid"/&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/StackPanel&gt; &lt;/ControlTemplate&gt; &lt;/UserControl.Resources&gt; &lt;Path x:Name="RibbonItem" Cursor="Hand"&gt; &lt;Path.Fill&gt; &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#FF66CC33"/&gt; &lt;GradientStop Color="#FF339900" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Path.Fill&gt; &lt;ToolTipService.ToolTip&gt; &lt;ToolTip x:Name="RibbonItemTooltip" Content="" Foreground="#FFFFFFFF" FontSize="9.333" Placement="Mouse" Template="{StaticResource ToolTipControlTemplateTimelineView}"/&gt; &lt;/ToolTipService.ToolTip&gt; &lt;Path.Data&gt; &lt;GeometryGroup x:Name="RibbonItemGeometryGroup"&gt; &lt;RectangleGeometry x:Name="RibbonItemBackground" /&gt; &lt;/GeometryGroup&gt; &lt;/Path.Data&gt; &lt;/Path&gt; &lt;/UserControl&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload