2014-01-17 59 views
1

当前我的RadDatagrid1对RadDatagrid1具有Cell_click操作,并且当选择ClientName时,该客户端信息投影到DataGrid2中。鼠标双击之内 码点击:与Datagrids的反应性用户界面

private void Cell_click(object sender, GridViewSelectedCellsChangedEventArgs e) 
{ 
    Var Details = (from info in contacts 
        where info.ClientName = sender.CurrentCell.ToString() 
        select new {info.ClientName, info.ClientAddress, Info.ClientNumber}); 
    DataGrid2.ItemsSource = Details.ToList(); 
} 

这是目前我有什么,但是,它应该是一个反应UI。 reactitve UI的一个例子,我被告知要看看这是在GridViewModel:

this.WhenAny(x => x.Forename, x => x.Surname, x => x.City, (p1, p2, p3) => Unit.Default).Subscribe(x => Filter()); 

但是,这并不完全意义的我。如果我能得到指导和技巧如何将其转换为反应式UI请。

回答

0

我是Reactive UI的新手,由于缺少文档,迄今为止我的经验一直是通过试验和错误。所以我下面的方法可能不正确。

确保你有一个视图模型支持您的WPF控件(参见this page

您的视图模型应该是这个样子:

public class ViewModel : ReactiveObject { 
    // ClientInfo type is the type of object you want to bind to the DataGrid 
    private ClientInfo clientInfo; 

    public ClientInfo ClientInfo { 
     set { this.RaiseAndSetIfChanged(ref clientInfo, value); } 
     get { return clientInfo; } 
    } 

    // Move contacts IEnumerable/IQueryable to your ViewModel 
    private IQueryable<ClientInfo> contacts; 

    public LoadInfo(string clientName) { 
     ClientInfo = (from info in contacts 
        where info.ClientName = clientName 
        select new {info.ClientName, info.ClientAddress, Info.ClientNumber}) 
    }  
} 

确保您的视图(控制类)实现IViewFor<T>其中T是您的视图模型的类型。根据文档here绑定视图。

做这样的事情你的观点:

// Implement the methods on that interface, which I will not include below 
public partial class View : IViewFor<ViewModel> { 

    private ICommand loadClientInfo; 

    public View() { // constructor 
     InitializeComponent(); // Don't forget this 

     // Binds the data in your ViewModel with the ItemSource of your DataGrid 
     this.OneWayBind(ViewModel, vm => vm.ClientInfo, x => x.DataGrid2.ItemSource); 
    } 

    private void Cell_click(object sender, GridViewSelectedCellsChangedEventArgs e) 
    { 
     ViewModel.LoadInfo(sender.CurrentCell.ToString()); 
    } 
}