MediaTimeline 中的绑定源
我试图将媒体时间线绑定到 Uri,如下所示:
<UserControl.Resources>
<Storyboard x:Key="myStoryboard">
<MediaTimeline Storyboard.TargetName="myMediaPlayer"
Source="{Binding MediaSource}"
RepeatBehavior="Forever" />
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource myStoryboard}" />
</EventTrigger>
</UserControl.Triggers>
<Grid>
<MediaElement x:Name="mymediaPlayer" />
</Grid>
但是,当我这样做时,它说我需要“必须指定 URI”。调度员异常。在视图模型中,我有一个如下属性:
public Uri MediaSource
{
get { return _mediaSource; }
set
{
if (_oscilloscopeSource != value)
{
_mediaSource= value;
OnPropertyChanged("MediaSource");
}
}
}
似乎加载媒体播放器时,它不会从绑定中读取源。什么给?
在构造函数中,我有:
_mediaSource = new Uri(@"C:\someMovie.mov", UriKind.Absolute);
谢谢。
I am trying to have the mediatimeline bind to a Uri like so:
<UserControl.Resources>
<Storyboard x:Key="myStoryboard">
<MediaTimeline Storyboard.TargetName="myMediaPlayer"
Source="{Binding MediaSource}"
RepeatBehavior="Forever" />
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource myStoryboard}" />
</EventTrigger>
</UserControl.Triggers>
<Grid>
<MediaElement x:Name="mymediaPlayer" />
</Grid>
However, when I do this, it says that I need to "Must Specify URI." Dispatcher exception. In the viewmodel, I have a property like:
public Uri MediaSource
{
get { return _mediaSource; }
set
{
if (_oscilloscopeSource != value)
{
_mediaSource= value;
OnPropertyChanged("MediaSource");
}
}
}
It seems as though when the media player is loaded, it doesn't read the source from the binding. What gives?
In the constructor, I have:
_mediaSource = new Uri(@"C:\someMovie.mov", UriKind.Absolute);
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新
无法让它工作,所以现在在黑暗中拍摄。将触发器移至 MediaElement 会产生影响吗?
我尝试过这个,它对我有用。我能想到的可能原因。
除了我更改的 MediaElement 名称之外,我的工作 xaml 与您的相同。这是我的完整代码隐藏文件
Update
Can't get this to work so shooting in the dark now. Does moving the trigger to MediaElement make a difference?
I tried this out and it works for me. Possible reasons I can think of.
Except for the MediaElement Name which I changed, my working xaml is identical to yours. This is my full code behind file