ラベルのターゲット プロパティを使用して ComboBox に接続する Silverlight 3 ラベルがあります。MSDN によると、Label クラスはターゲット バインディングを反復処理し、ソースでメタ データを検索して、Label のコンテンツを決定します。
これは、ターゲットが標準コントロールである限り、実際に機能します。しかし、私の場合は ComboBox を拡張するカスタム コントロールを使用し、新しい DependencyProperty を導入すると、単純に無視されます。
たとえば、これは機能します:
<dataInput:Label Grid.Row="3" Grid.Column="0"
Target="{Binding ElementName=cbxCountry}"
VerticalAlignment="Center"/>
<ComboBox x:Name="cbxCountry" DisplayMemberPath="Name"
SelectedItem="{Binding DataModel.Country, Mode=TwoWay}"
ItemsSource="{Binding Countries, Source={StaticResource ApplicationData}}"/>
上記の例では、SelectedItem Binding が検索され、DataModel.Country には取得された DisplayName が含まれています。
しかし、これはしません:
<dataInput:Label Grid.Row="3" Grid.Column="0"
Target="{Binding ElementName=cbxCountry}"
VerticalAlignment="Center"/>
<local:MyComboBox x:Name="cbxCountry" DisplayMemberPath="Name"
MySelectedItem="{Binding DataModel.Country, Mode=TwoWay}"
MyItemsSource="{Binding Countries, Source={StaticResource ApplicationData}}"/>
カスタム プロパティは依存関係プロパティであり、次のように宣言されます。
private static readonly DependencyProperty MySelectedItemProperty =
DependencyProperty.Register("MySelectedItem",
typeof(object), typeof(MyComboBox),
new PropertyMetadata(null,
MySelectedItemPropertyChanged));
Label に PropertyPath を定義することでこれを回避できることはわかっていますが、できればこれは避けたいと思います。
だから私の質問は、誰でもこの問題を再現できるかということです。もちろん、もっと重要なのは、誰もそれを解決する方法を知っていますか? :-)
ありがとう、マーカス