English 中文(简体)
4. 对附属财产具有约束力的数据
原标题:Silverlight 4.0 Databinding to a Dependency Property

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)

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

最佳回答

答案很简单。 本条:

<my:PagingControl Jake="{Binding AthleteMaxes}" />

Jake将与数据组装在一起。 但是,在创建用户委员会时,你正在将数据内容与其他内容联系起来!

<UserControl x:Name="rootElement" DataContext="{Binding PagingControlVM, Source=StaticResource Locator}}">

因此,现在,Jake必须服从PagingControlVM。 At:

问题回答

暂无回答




相关问题
How to bind a TabControl to an ObservableCollection in XAML

I have the following line of code in my code-behind class. TabControl.ItemsSource = ((MainWindowViewModel)DataContext).TabItemViewModels; I would like to move this to the XAML file. In brief, ...

Bind to ancestor of adorned element

Here is the case: <DataTemplate x:Key="ItemTemplate" DataType="local:RoutedCustomCommand"> <Button Command="{Binding}" Content="{Binding Text}" ...

LINQ to SQL as databinding source for WPF Treeview

I wonder if someone could provide a simple example of the following. (preferably in VB.Net): I have an SQL database with related tables and I am successfully using LINQ to SQL in other areas of my ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

WPF TreeView binding through XAML

So I have a class structure like this Store Owner Cashier List of Products Product Name Price List of Vendors Company Name Contact Name So there are 4 ...

热门标签