我试图让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”。调度程序异常。在viewmodel中,我有一个属性:
public Uri MediaSource
{
get { return _mediaSource; }
set
{
if (_oscilloscopeSource != value)
{
_mediaSource= value;
OnPropertyChanged("MediaSource");
}
}
}
似乎在加载媒体播放器时,它不会从绑定中读取源。是什么给了什么?
在构造函数中,我有:
_mediaSource = new Uri(@"C:\someMovie.mov", UriKind.Absolute);
感谢。
答案 0 :(得分:4)
<强>更新强>
现在无法让这个工作在黑暗中拍摄。将触发器移动到MediaElement会有所作为吗?
<MediaElement x:Name="myMediaPlayer">
<MediaElement.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource myStoryboard}" />
</EventTrigger>
</MediaElement.Triggers>
</MediaElement>
我尝试了这个,它对我有用。我能想到的可能原因。
除了我更改的MediaElement名称,我的工作xaml与你的相同。这是我的完整代码文件
public partial class UserControl1 : UserControl, INotifyPropertyChanged
{
public UserControl1()
{
InitializeComponent();
MediaSource = new Uri("C:\\C1.MOV");
this.DataContext = this;
}
private Uri _mediaSource;
public Uri MediaSource
{
get
{
return _mediaSource;
}
set
{
_mediaSource = value;
OnPropertyChanged("MediaSource");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}