1
我有一個Silverlight 3標籤,我使用標籤的目標屬性連接到組合框。根據MSDN,Label類遍歷目標綁定並搜索源數據以確定標籤的內容。Silverlight:標籤不評估自定義綁定DependencyProperty
只要目標是一個標準控件,這實際上是有效的。但是,如果我使用自定義控件(在我的情況下擴展了ComboBox),並引入了新的DependencyProperty,它將被忽略。
E.g.這工作:
<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綁定搜索和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}}"/>
自定義屬性是依賴屬性,並宣佈爲follws:
private static readonly DependencyProperty MySelectedItemProperty =
DependencyProperty.Register("MySelectedItem",
typeof(object), typeof(MyComboBox),
new PropertyMetadata(null,
MySelectedItemPropertyChanged));
我知道我可以解決這個定義上的標籤的PropertyPath,但如果可能的話,我寧願避免這種情況。
所以我現在的問題是,任何人都可以重現這個問題,當然更重要的是,有誰知道如何解決它? :-)
謝謝,馬庫斯