I have a control in which I cannot access the code, and I believe that this is because it is defined in the DataTempalte.
General control - slide show carousel. Each slide can be an image or a media element (video), the content of which is defined in the ItemSource binding. The carousel is on the timer to switch from one slide to another. Every time the slide changes, I fire an event for this.
When I click on a video slide, I would like to stop the slide timer (do it) and start the video in which I encountered a problem. I cannot access the MediaPlayer Name element from my code. My guess at this point is that this is a DataTemplate.
Is this assumption correct? If so, how can I access this control with a code or (moreover) if it starts playing when a slide appears?
<ctrl:AutoScrollCarousel ...> <ctrl:AutoScrollCarousel.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ctrl:AutoScrollCarousel.ItemsPanel> <ctrl:AutoScrollCarousel.ItemTemplate> <DataTemplate> <Border x:Name="Border" VerticalAlignment="Center" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor}}"> <Grid Background="White"> ... <Image Source="{Binding ContentImage}" Grid.Row="1" Grid.Column="1" Stretch="UniformToFill" HorizontalAlignment="Center" Visibility="{Binding ContentImage, Converter={StaticResource VisibilityConverter}}" /> <MediaElement Name="MediaPlayer" Source="{Binding ContentVideo}" Grid.Row="1" Grid.Column="1" Stretch="UniformToFill" LoadedBehavior="Play" Visibility="{Binding ContentVideo, Converter={StaticResource VisibilityConverter}}" MediaEnded="MediaPlayer_MediaEnded" /> <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Title}" Foreground="Black" FontFamily="Segoe UI" FontWeight="Light" HorizontalAlignment="Left" FontSize="75" Margin="0" VerticalAlignment="Center" /> <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding ContentHeadline}" Foreground="Black" FontFamily="Segoe UI" FontWeight="Light" HorizontalAlignment="Left" FontSize="50" VerticalAlignment="Center" TextWrapping="Wrap"> </TextBlock> </Grid> </Border> </DataTemplate> </ctrl:AutoScrollCarousel.ItemTemplate> </ctrl:AutoScrollCarousel>
source share