WPF视频播放

部署运行你感兴趣的模型镜像

在这里插入图片描述

<!-- Declare the MyVideos class, which belongs to the DataTemplatingLab namespace.-->
<!-- Setting the Directory to the relative path pointing to the Media folder.-->
<!-- Giving this an x:Key. Now controls in this Window can bind to the videos in the Media folder.-->
<Window.Resources>
    <local:MyVideos Directory="../../media" x:Key="Vids" />

    <DataTemplate x:Key="MainScreenTemplate">
        <Border BorderBrush="LimeGreen" BorderThickness="2"
                CornerRadius="3" Margin="15">
            <Grid>
                <!-- Background image if no video is playing. -->
                <Image Source="Images\Crystal.jpg" Stretch="Fill" />
                <!-- The video -->
                <!-- The Source property of the video is bound to the Source property of the current MyVideo object.-->
                <MediaElement Name="mainVideo" Stretch="Fill"
                              Source="{Binding Path=Source}" />
            </Grid>
        </Border>
    </DataTemplate>

    <!-- Must be placed above listBoxTemplate -->
    <ToolTip x:Key="PreviewScreen" x:Shared="True" Background="Transparent"
             Placement="Right" Name="previewToolTip">
        <Border BorderBrush="RoyalBlue" BorderThickness="2" CornerRadius="2">
            <MediaElement Source="{Binding Path=Source}"
                          Opacity="0.8" IsMuted="True" />
        </Border>
    </ToolTip>

    <DataTemplate x:Key="ListBoxTemplate">
        <DataTemplate.Resources>
            <Style TargetType="DockPanel">
                <Setter Property="Cursor" Value="Hand" />
                <Setter Property="ToolTipService.ShowDuration" Value="80000" />
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="ToolTip" Value="{StaticResource PreviewScreen}" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataTemplate.Resources>
        <DockPanel Height="70" Width="160">
            <Border Margin="4,5,0,0" Height="50" Width="50">
                <Image Source="Images\Preview.png" />
            </Border>
            <TextBlock Text="{Binding Path=VideoTitle}" VerticalAlignment="Center"
                       TextBlock.TextTrimming="WordEllipsis" Margin="5,5,0,5"
                       Foreground="White" FontSize="12" FontFamily="Comic Sans MS" />
        </DockPanel>
    </DataTemplate>

    <Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
        <Setter Property="Margin" Value="10,10,10,0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Grid>
                        <Rectangle x:Name="GelBackground" RadiusX="9" RadiusY="9"
                                   Opacity="1" Fill="{TemplateBinding Background}"
                                   Stroke="#66ffffff" StrokeThickness="1" />
                        <Rectangle x:Name="GelShine" RadiusX="6" RadiusY="6"
                                   Opacity="1" Margin="2,2,2,0" VerticalAlignment="top"
                                   Stroke="transparent" Height="15">
                            <Rectangle.Fill>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                    <GradientBrush.GradientStops>
                                        <GradientStopCollection>
                                            <GradientStop Color="#ccffffff" Offset="0" />
                                            <GradientStop Color="transparent" Offset="1" />
                                        </GradientStopCollection>
                                    </GradientBrush.GradientStops>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <EventTrigger RoutedEvent="Mouse.MouseEnter">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard TargetName="GelBackground"
                                                TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                                        <ColorAnimation To="LimeGreen" Duration="0:0:0.1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="Mouse.MouseLeave">
                            <EventTrigger.Actions>
                                <BeginStoryboard>
                                    <Storyboard TargetName="GelBackground"
                                                TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                                        <ColorAnimation Duration="0:0:0.1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger.Actions>
                        </EventTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="true">
                <Setter Property="Background" Value="RoyalBlue" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>

<!-- 1) The ListBox and ContentControl bind to the same source. -->
<!-- 2) IsSynchronizedWithCurrentItem set to true. -->
<!-- With the above 2 conditions satisfied, once the DataTemplates are in place,
   the ContentControl will display the content of the selected list item.-->
<DockPanel>
    <ListBox DockPanel.Dock="Left" Width="200" BorderThickness="0"
             ItemsSource="{Binding Source={StaticResource Vids}}"
             IsSynchronizedWithCurrentItem="True"
             ItemTemplate="{StaticResource ListBoxTemplate}"
             Background="Transparent" />
    <ContentControl Content="{Binding Source={StaticResource Vids}}"
                    ContentTemplate="{StaticResource MainScreenTemplate}" />
</DockPanel>

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向着光-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值