XAMLの要素にカスタム属性を追加する手順に従いましたか?しかし、残念ながら、デザイナーから要素が見つからないと言われ、プログラムを起動すると、「不明なメンバーを設定できません」というメッセージとともにXamlParserExceptionが発生します'{clr-namespace:myNs}MediaElementProperties.MediaId'。
私のセットアップ:
- 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); } }}
なぜ私が例外を取得し続けるのか、何か考えがありますか?