我想要的屬性,我DataContext
在ValidationRule
綁定到一個屬性:基於this threadWPF,在有效性規則屬性從未
public class ReleaseValidationRule : ValidationRule
{
// I want to bind a value from my DataContext to this property:
public CheckboxViewModels ValidReleases { get; set; }
...
}
,我創建了CheckboxViewModels
類只是充當一個包裝爲List<CheckboxViewModel>
,以便該列表可以是DependencyProperty
,以便我可以綁定到它。但是,在我的ValidationRule
的Validate
方法中,ValidReleases
列表始終爲空。這是我的XAML:
<TextBox>
<TextBox.Text>
<Binding Path="Release" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:ReleaseValidationRule>
<local:ReleaseValidationRule.ValidReleases>
<local:CheckboxViewModels List="{Binding Path=Releases,
Converter={StaticResource debugConverter}}"/>
</local:ReleaseValidationRule.ValidReleases>
</local:ReleaseValidationRule>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
我知道Releases
財產(就是我結合的CheckboxViewModels
的List
物業)擁有的內容,因爲我有一個TreeView
只是TextBox
顯示的Releases
上面的內容。我在CheckboxViewModels.List
綁定上的轉換器什麼都不做,它只是一個我可以設置斷點的地方。有趣的是,轉換器斷點永遠不會被擊中。就好像整個行<local:CheckboxViewModels List="{Binding Path=Releases, Converter={StaticResource debugConverter}}"/>
從未得到執行,因此我的ValidationRule
中的ValidReleases
屬性永遠不會被設置。這是怎麼回事?
編輯:這裏的CheckboxViewModels
樣子:
public class CheckboxViewModels : DependencyObject, IList<CheckboxViewModel>,
IEnumerable<CheckboxViewModel>
{
...members necessary to implement IList, IEnumerable...
public static readonly DependencyProperty ListProperty =
DependencyProperty.Register(
"List",
typeof(List<CheckboxViewModel>),
typeof(CheckboxViewModels),
new PropertyMetadata(new List<CheckboxViewModel>())
);
public List<CheckboxViewModel> List
{
get { return (List<CheckboxViewModel>)GetValue(ListProperty); }
set { SetValue(ListProperty, value); }
}
}
我更新了我的問題,包括'CheckboxViewModels'代碼。我不確定我應該聯繫哪些事件。 – 2010-08-26 18:52:01
我沒有看到一個要求使列表成爲DP,因爲它看起來像綁定源而不是目標。我現在要添加一個新的屬性ObservableCollection,然後嘗試用它重新解決這個問題。你可以把它稱之爲像Releases_NEW那樣聰明,併發布任何綁定給你帶來麻煩。如果DP需要變得清晰,我就會看到一條嘗試並使之發揮作用的途徑,而且您仍然有一個起點。 –
Berryl
2010-08-26 23:33:47