WPF MediaElement ActualWidth 和 ActualHeight 始终为零

发布于 2024-08-09 20:14:03 字数 683 浏览 5 评论 0原文

由于某些未知原因,当我在 ControlTemplate 中使用我的 MediaElement 时,我无法显示它。

我已经安装了 snoop,并且确定 ActualWidthActualHeight 始终为零,如果我将相同的媒体元素随机放置在主窗口上,它确实显示。

那么,为什么它总是为零?这简直要死我了!!

这是我在 ControlTemplate 中的 xaml:

<MediaElement x:Name="frostElement" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Stretch="Fill"
        LoadedBehavior="Play"
        Width="{TemplateBinding Width}" 
        Height="{TemplateBinding Height}" 
        Margin="0,0,0,26.083" 
        Source="../Images/ice.mpg"/>

另外,如果我手动设置宽度和高度,它仍然不会显示。

For some unknown reason I cannot get my MediaElement to show up when I use it in a ControlTemplate.

I have installed snoop and I have determined that the ActualWidth and ActualHeight is always zero, if I put the same media element on the main window just randomly placed, it does show.

So, why the heck would it always be zero?? This is killing me!!

here is my xaml in the ControlTemplate:

<MediaElement x:Name="frostElement" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Stretch="Fill"
        LoadedBehavior="Play"
        Width="{TemplateBinding Width}" 
        Height="{TemplateBinding Height}" 
        Margin="0,0,0,26.083" 
        Source="../Images/ice.mpg"/>

Also, if I set the width and height manually, it still doesnt show up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的轨迹 2024-08-16 20:14:03

呸!我发现,这是一个资源问题,我输入了文件的完整路径(c:..blah)并且它起作用了。

Bah! I figured it out, it was a resource issue, I put in the full path to the file (c:..blah) and it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文