我按照從Adding custom attributes to an element in XAML?的指示,但不幸的是設計者告訴我,他無法找到該元素,當啓動程序時,我得到一個XamlParserException與消息無法設置未知成員'{clr-命名空間:myns名字} MediaElementProperties.MediaId」。附加屬性拋出ParseException
我的設定:
- XAML的頁與該命令
XamlReader.Load(fileStream)
動態加載用於顯示 內容頁本身,它使用這樣的代碼:
<MediaElement myNs:MediaElementProperties.MediaId="test" ... />
其中myns名字用
xmlns:myNs="clr-namespace:MyNamespace"
定義
而且MediaElementProperties看起來像這樣的定義:
namespace MyNamespace { public static class MediaElementProperties { public static readonly DependencyProperty MediaIdProperty = DependencyProperty.Register("MediaId", typeof(string), typeof(MediaElementProperties), new FrameworkPropertyMetadata(string.Empty)); public static string GetMediaId(UIElement element) { return (string)element.GetValue(MediaIdProperty); } public static void SetMediaId(UIElement element, string value) { element.SetValue(MediaIdProperty, value); } }}
你有什麼想法,爲什麼我不斷收到異常?
你嘗試過關閉所有的設計師,清洗解決方案,並重建它? –
你試過'DependencyProperty.RegisterAttached',而不是'DependencyProperty.Register'? – Zabavsky
試了一下。沒有修復它。設計師還在說 –