【问题标题】:Playing video in Silverlight with Source binding使用源绑定在 Silverlight 中播放视频
【发布时间】:2011-10-07 20:00:08
【问题描述】:

我正在尝试制作要在 Silverlight MediaElement 中播放的 WMV 视频。它适用于此 XAML 代码:

        <MediaElement
        x:Name="VideoElement"
        Stretch="Fill"
        Source=""http://ecn.channel9.msdn.com/o9/pdc09/wmv/CL20.wmv""
        Grid.Row="0"
        Grid.Column="0"
        AutoPlay="True"/>

但是当我尝试将源绑定到我的代码中的某些属性时:

        <MediaElement
        x:Name="VideoElement"
        Stretch="Fill"
        Source="{Binding VidPath}"
        Grid.Row="0"
        Grid.Column="0"
        AutoPlay="True"/>

VidPath 在哪里:

    public Uri VidPath
    {
        get
        {
            return new Uri("http://ecn.channel9.msdn.com/o9/pdc09/wmv/CL20.wmv", UriKind.Absolute);
        }
        set;
    }

它不起作用。你能帮我找出原因吗?

【问题讨论】:

    标签: silverlight xaml binding


    【解决方案1】:

    首先,我假设这是一个完全信任的浏览器外应用程序,否则跨域策略限制会阻止 MediaElement 以任何方式播放该视频。

    鉴于此,您提供的代码没有任何问题,但我预感包含您的 MediaPlayer 的页面的 DataContext 设置不正确。如果你在 VidPath 的 getter 中设置一个断点,它会被命中吗?我打赌没有。

    无论什么对象包含您的“VidPath”属性,您都需要确保它是您页面的 DataContext。例如。如果您只是将 VidPath 作为属性放在代码隐藏中,则可以将其添加到构造函数中:

    this.DataContext = this;
    

    【讨论】:

    • 是的,就是这样。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多