Note that there are some explanatory texts on larger screens.

plurals
  1. POGet button in Pivot Header programatically in Windows Phone 8
    primarykey
    data
    text
    <p>Summary: I need to retrieve a button (in order to attach a click handler) from a pivot of which template is defined as static resource. How can I do this?</p> <p>A couple of views contain a pivot control, and style of these pivots are defined in App.xaml as resource.</p> <p>Here is XAML for Pivot in multiple pages:</p> <pre><code>&lt;phone:Pivot Title="Onaylar" Name="pivot" Style="{StaticResource MyPivotStyle}"&gt; &lt;phone:PivotItem Header="first pivot item"&gt; &lt;TextBlock Foreground="{StaticResource NavyTextColor}" Margin="10,0,0,0" Text="first pivot item"&gt;&lt;/TextBlock&gt; &lt;/phone:PivotItem&gt; &lt;phone:PivotItem Header="second pivot item"&gt; &lt;TextBlock Foreground="{StaticResource NavyTextColor}" Margin="10,0,0,0" Text="second pivot item"&gt;&lt;/TextBlock&gt; &lt;/phone:PivotItem&gt; &lt;phone:PivotItem Header="third pivot item"&gt; &lt;TextBlock Foreground="{StaticResource NavyTextColor}" Margin="10,0,0,0" Text="third pivot item"&gt;&lt;/TextBlock&gt; &lt;/phone:PivotItem&gt; &lt;/phone:Pivot&gt; </code></pre> <p>Here is the style for pivot defined in App.xaml (shortened for convenience):</p> <pre><code>&lt;Style x:Key="MyPivotStyle" TargetType="phone:Pivot"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="phone:Pivot"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;RowDefinition Height="Auto"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid CacheMode="BitmapCache" Grid.RowSpan="2"&gt; &lt;Grid.Background&gt; &lt;ImageBrush ImageSource="/Assets/bg_header.png"/&gt; &lt;/Grid.Background&gt; &lt;/Grid&gt; &lt;Grid Background="{TemplateBinding Background}" CacheMode="BitmapCache" Grid.Row="2" /&gt; &lt;ContentPresenter ContentTemplate="{TemplateBinding TitleTemplate}" Margin="24,17,0,-7"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="/Assets/company_name.png" Width="213.75" HorizontalAlignment="Left" VerticalAlignment="Top" /&gt; &lt;Button HorizontalAlignment="Right" VerticalAlignment="Top" Margin="140,-20,0,35" BorderThickness="0" x:Name="btnHome"&gt; &lt;Image Source="/Assets/btnHome.png" Width="48" Height="48" &gt;&lt;/Image&gt; &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/ContentPresenter&gt; &lt;controlsPrimitives:PivotHeadersControl x:Name="HeadersListElement" Foreground="White" Grid.Row="1"/&gt; &lt;ItemsPresenter x:Name="PivotItemPresenter" Margin="{TemplateBinding Padding}" Grid.Row="2"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>What I want to do is this:</p> <pre><code>var myButton = GetButtonWithName("btnHome") as Button; myButton.Click += Handler; </code></pre> <p>However, I cannot get the button. Any solutions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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