我想将媒体元素的位置绑定到它的模型视图。我知道该属性不是依赖属性。于是就这样试了一下,网上找的一个代码
<MediaElement Source="{Binding CurrentClip.Path, Converter={StaticResource converter}, UpdateSourceTrigger=PropertyChanged}" Stretch="Uniform" local:MediaElementHelper.Postion="{Binding CurrentClip.Postion}"
媒体元素助手
class MediaElementHelper
{
public static readonly DependencyProperty PostionProperty =
DependencyProperty.RegisterAttached("Position",
typeof(bool), typeof(MediaElement),
new FrameworkPropertyMetadata(false, PostionPropertyChanged));
private static void PostionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var richEditControl = obj as MediaElement;
if (richEditControl != null)
{
richEditControl.Position = (TimeSpan)e.NewValue;
}
}
public static void SetPostion(UIElement element, TimeSpan value)
{
element.SetValue(PostionProperty, value);
}
public static TimeSpan GetPostion(UIElement element)
{
return (TimeSpan)element.GetValue(PostionProperty);
}
}
[错误] 无法在“MediaElement”类型的“SetPostion”属性上设置“绑定”。只能在 DependencyObject 的 DependencyProperty 上设置“绑定”。
我究竟做错了什么?