私はWindows8ストアアプリのGridAppのitemsdetailページのフリップビュー内でMediaElementControlを使用していますが、それを使用する際に特有のタイプの問題に直面しています。MediaElementはビデオを表示しませんが、目的のビデオ出力には黒い画面しかありませんが、ビデオのオーディオは問題なく再生されます。
今、私の問題の特有の部分は、グリッドアプリにグループ内のアイテムのコレクションがあることです(私は自分自身を明確にするために、これを知っているかもしれません)、すべてのグループの最初のアイテムはちょうどビデオを再生します罰金私はそれがビデオとオーディオをうまく表示することを意味しますが、グループの残りのアイテムはビデオを表示せず、ビデオのオーディオを再生するだけです。なぜこれが起こっているのか誰かが知っていますか?
XAMLコードは次のとおりです。
<FlipView
x:Name="flipView"
AutomationProperties.AutomationId="ItemsFlipView"
AutomationProperties.Name="Item Details"
TabIndex="1"
Grid.RowSpan="2"
ItemsSource="{Binding Source={StaticResource itemsViewSource}}">
<FlipView.ItemContainerStyle>
<Style TargetType="FlipViewItem">
<Setter Property="Margin" Value="0,137,0,0"/>
</Style>
</FlipView.ItemContainerStyle>
<FlipView.ItemTemplate>
<DataTemplate>
<UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
<ScrollViewer x:Name="scrollViewer" Style="{StaticResource VerticalScrollViewerStyle}" Grid.Row="1">
<Grid Margin="120,0,20,20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400" />
<ColumnDefinition Width="40" />
<ColumnDefinition Width="360" />
<ColumnDefinition Width="40" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border BorderBrush="Black" BorderThickness="1" Width="350" HorizontalAlignment="Left" Grid.Row="0">
<MediaElement x:Name="VideoSource" AutomationProperties.Name="VideoSource" Source="/Assets/Big_Buck_Bunny.mp4" HorizontalAlignment="Center" VerticalAlignment="Stretch" Height="250" Width="350" AutoPlay="False" IsLooping="True" />
</Border>
<Border BorderBrush="Black" BorderThickness="1" Height="65" Width="350" HorizontalAlignment="Left" Grid.Row="1">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="playButton" Margin="0,0" Click="playButton_Click" Style="{StaticResource PlayAppBarButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button x:Name="pauseButton" Margin="0,0" Click="pauseButton_Click" Style="{StaticResource PauseAppBarButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Border>
</Grid>
</ScrollViewer>
</UserControl>
</DataTemplate>
</FlipView.ItemTemplate>
これが背後にあるコードです:
private void playButton_Click(object sender, RoutedEventArgs e)
{
MediaElement media = FindControl<MediaElement>(this, "VideoSource") as MediaElement;
media.Play();
}
private void pauseButton_Click(object sender, RoutedEventArgs e)
{
MediaElement media = FindControl<MediaElement>(this, "VideoSource") as MediaElement;
media.Pause();
}
private void stopButton_Click(object sender, RoutedEventArgs e)
{
MediaElement media = FindControl<MediaElement>(this, "VideoSource") as MediaElement;
media.Stop();
}
private DependencyObject FindControl<T>(DependencyObject controlType, string ctrlName)
{
int childNumber = VisualTreeHelper.GetChildrenCount(controlType);
for (int i = 0; i < childNumber; i++)
{
DependencyObject child = VisualTreeHelper.GetChild(controlType, i);
FrameworkElement fe = child as FrameworkElement;
// Not a framework element or is null
if (fe == null) return null;
if (child is T && fe.Name == ctrlName)
{
// Found the control so return
return child;
}
else
{
// Not found it - search children
DependencyObject nextLevel = FindControl<T>(child, ctrlName);
if (nextLevel != null)
return nextLevel;
}
}
return null;
}
問題を明確にしたいと思います。