WPF: MediaElement doesn't display at runtime

ⅰ亾dé卋堺 提交于 2019-12-24 16:14:30

问题


This concerns WPF. The problem is that my MediaElement (actually a GIF) doesn't show up at runtime (so I only get an empty screen), even though it shows perfectly in the design mode. Before citing the code I note the following:

  • The GIF-file in question has been added to the solution.
  • Its BuildAction property is set to Resource (I've checked).
  • When I replace the MediaElement by an Image element (and either use the same GIF-file or replace that source-file by a .png file), the image/GIF does display at runtime. Just not when it's used as a MediaElement.
  • Closing and re-starting Visual Studio doesn't help.
  • As I said (and just to emphasize, if I may), the GIF image does display in the design mode part of the screen - just not at runtime.

And here's the code:

     <Window x:Class="Testing.TestWindow" 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                xmlns:local="clr-namespace:Testing"
                mc:Ignorable="d"
                Title="TestWindow" WindowState="Maximized">
        <StackPanel>
            <MediaElement Source="pack://application:,,,/Images/untitled.gif" Stretch="Fill" Visibility="Visible" />
        </StackPanel>
    </Window>

Thanks.

来源:https://stackoverflow.com/questions/34386658/wpf-mediaelement-doesnt-display-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!