Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Access a Button present inside a Custom Control, from the implementing page?
    primarykey
    data
    text
    <p>I have my generic.xaml containing the following code:</p> <pre><code>&lt;ControlTemplate TargetType="local:customVideoControl"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="600"/&gt; &lt;RowDefinition Height="200"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="200"/&gt; &lt;ColumnDefinition Width="200"/&gt; &lt;ColumnDefinition Width="200"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;MediaElement x:Name="customMediaPlayer" Source="{TemplateBinding CustomMediaSource}" HorizontalAlignment="Center" VerticalAlignment="Center" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Grid.Row="0" Grid.ColumnSpan="3" /&gt; &lt;ToggleButton x:Name="playPauseBtn" Height="50" Width="50" Content="Pause" Grid.Row="1" Grid.Column="0"/&gt; &lt;Button x:Name="prevBtn" Height="50" Width="50" Content="Prev" Grid.Row="1" Grid.Column="1"/&gt; &lt;Button x:Name="nextBtn" Height="50" Width="50" Content="Next" Grid.Row="1" Grid.Column="2"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; </code></pre> <p>Now on applyTemplate , I am accessing the controls like below:</p> <pre><code> public override void OnApplyTemplate() { base.OnApplyTemplate(); ToggleButton playPauseBtn = GetTemplateChild("playPauseBtn") as ToggleButton; Button prevBtn= GetTemplateChild("prevBtn") as Button; Button nextBtn = GetTemplateChild("nextBtn") as Button; MediaElement customMediaPlayer = GetTemplateChild("customMediaPlayer") as MediaElement; playPauseBtn.Checked += (obj, Args) =&gt; { customMediaPlayer.Pause(); playPauseBtn.Content = "Play"; }; playPauseBtn.Unchecked += (obj, Args) =&gt; { customMediaPlayer.Play(); playPauseBtn.Content = "Pause"; }; nextBtn.Click += (obj, Args) =&gt; { customMediaPlayer.Source=new Uri(CustomMediaSource.ToString(),UriKind.RelativeOrAbsolute); }; prevBtn.Click += (obj, Args) =&gt; { customMediaPlayer.Source = new Uri(CustomMediaSource.ToString(), UriKind.RelativeOrAbsolute); }; } </code></pre> <p>Now I want acccess the nextBtn, in the page where I am implementing like </p> <pre><code>CustomVideoControl myVControl=new CustomVideoControl(); </code></pre> <p>This will create the instance of the control, but I want to do something on the click of next and previous button, thta is present inside the CustomVideoControl in generic.xaml. Any help will be greatly appreciated.</p> <p>Thanks, Subhen</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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