I'm trying to bind a property in my DataContext
to a property in a ValidationRule
:
public class ReleaseValidationRule : ValidationRule
{
// I want to bind a value from my DataContext to this property:
public CheckboxViewModels ValidReleases { get; set; }
...
}
Based on this thread, I created the CheckboxViewModels
class just to act as a wrapper for a List<CheckboxViewModel>
so that the list could be a DependencyProperty
so that I could bind to it. However, in my Validate
method on my ValidationRule
, the ValidReleases
list is always empty. Here's my 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>
I know the Releases
property (what I'm binding to the List
property of CheckboxViewModels
) has content because I have a TreeView
just above the TextBox
that shows the contents of Releases
. The converter I have on the CheckboxViewModels.List
binding does nothing, it's just a place where I can set a breakpoint. The funny thing is, that converter breakpoint never gets hit. It's as if the whole line <local:CheckboxViewModels List="{Binding Path=Releases, Converter={StaticResource debugConverter}}"/>
never gets executed, so the ValidReleases
property in my ValidationRule
never gets set. What's going on?
Edit: here's what CheckboxViewModels
looks like:
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); }
}
}