I m having difficulty getting the binding to fire off on a user control that is nested inside of another use control. Here is my hierarchy:
- Navigation Page
- User Control A (AthleteMaxGrid)
- User Control B (PagingControl)
- User Control A (AthleteMaxGrid)
I m using the MVVM design model with the MVVMLight toolkit for these controls. Here is the situation: Both User Controls have corresponding ViewModels that are attached to them in the XAML. The View Model of AthleteMaxGrid has a Observable Collection (AthleteMaxes) property exposed that I wanted to bind to the PagingControl. This property is also being bound to in a dataview in the AthleteMaxGrid control, so it know its being populated correctly.
该守则是:
AthleteMaxGrid XAML:
<UserControl ...
DataContext="{Binding AthleteMaxGrid, Source={StaticResource Locator}}">
....
<StackPanel Orientation="Horizontal">
...
<my:PagingControl Jake="{Binding AthleteMaxes}" />
</StackPanel>
<telerik:RadGridView x:Name="rgvMaxes" IsScrolling="False"
ItemsSource="{Binding AthleteMaxes}" AutoGenerateColumns="False"
IsBusy="{Binding IsBusy}" >...
The is a snipit from the AthleteMaxGrid ViewModel:
public const string AllMaxesPropertyName = "AthleteMaxes";
private ObservableCollection<AthleteMaxTableItem> _allMaxes = new ObservableCollection<AthleteMaxTableItem>();
/// <summary>
/// Gets the AthleteMaxes property.
/// </summary>
public ObservableCollection<AthleteMaxTableItem> AthleteMaxes
{
get
{
return _allMaxes;
}
set
{
if (_allMaxes == value)
{
return;
}
_allMaxes = value;
// Update bindings, no broadcast
RaisePropertyChanged("AthleteMaxes");
}
}
Here is the XAML from PagingControl:
<UserControl ...
x:Name="rootElement"
DataContext="{Binding PagingControlVM, Source={StaticResource Locator}}">
...
</UserControl>
我在《代议制法典》中设立了附属财产,如:
public const string JakePropertyName = "Jake";
public object Jake
{
get
{
return (object)GetValue(JakeProperty);
}
set
{
SetValue(JakeProperty, value);
}
}
public static readonly DependencyProperty JakeProperty = DependencyProperty.Register(
JakePropertyName,
typeof(object),
typeof(PagingControl),
new PropertyMetadata(null,
new PropertyChangedCallback(onJakeChanged)));
private static void onJakeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show(d.GetType().ToString());
}
此时此刻,我只是试图打上我的“回击”功能,所以我知道数据正在适当输入,我可以进入我的控制约束的下一个阶段,但这种控制并没有受到打击。
如果我把XAML的面包房放在AthleteMaxGrid上,像“测试”这样简单一些,那么这种警示就会受到适当的打击。 看来这是对Model财产具有约束力的问题。
Any ideas?
Thanks in advance! Nick