C# 在Silverlight中使用棱镜模式重新绑定控件

C# 在Silverlight中使用棱镜模式重新绑定控件,c#,silverlight-3.0,prism,C#,Silverlight 3.0,Prism,我一直在尝试使用复合应用程序库(Prism),我已经建立了一个相当标准的模式,这是我遵循Microsoft教程的。基本上,视图被注入到区域中。视图是动态构建的,添加控件等等都是通过编程实现的 我有一个命令被触发,在回发时,我想重新绑定当前视图上的控件,而不是完全重新渲染所有控件 因此,我尝试用更新的版本更新模型,希望能强制重新绑定控件。那不行。我不确定我应该采取什么方法,因为我对Prism是新手 有什么想法吗 订阅事件以处理回发 IEventAggregator aggregator = thi

我一直在尝试使用复合应用程序库(Prism),我已经建立了一个相当标准的模式,这是我遵循Microsoft教程的。基本上,视图被注入到区域中。视图是动态构建的,添加控件等等都是通过编程实现的

我有一个命令被触发,在回发时,我想重新绑定当前视图上的控件,而不是完全重新渲染所有控件

因此,我尝试用更新的版本更新模型,希望能强制重新绑定控件。那不行。我不确定我应该采取什么方法,因为我对Prism是新手

有什么想法吗

订阅事件以处理回发

IEventAggregator aggregator = this.Container.Resolve<IEventAggregator>();
aggregator.GetEvent<DataInstanceLoadedEvent>().Subscribe(this.OnDataInstanceUpdated);

我已经想出了如何根据微软建议的模式重新绑定

基本上,我所要做的就是从模型上的INotifyPropertyChanged继承

然后按照这种模式,一旦我的模型更新了,就会通过触发一个事件来强制重新绑定所有控件,该事件通知客户机属性实际上已经更改

public class MyModel : INotifyPropertyChanged
{
    private DataInstance currentDataInstance;
    public event PropertyChangedEventHandler PropertyChanged;
    public DataInstance CurrentDataInstance
    {
        get
        {
            return this.currentDataInstance;
        }
        set
        {
            if ( this.currentDataInstance == value )
                return;
            this.currentDataInstance = value;
            this.OnPropertyChanged( new PropertyChangedEventArgs("CurrentDataInstance"));
        }
    }
    protected virtual void OnPropertyChanged( PropertyChangedEventArgs e )
    {
        if ( this.PropertyChanged != null )
            this.PropertyChanged( this, e );
    }
}
public class MyModel : INotifyPropertyChanged
{
    private DataInstance currentDataInstance;
    public event PropertyChangedEventHandler PropertyChanged;
    public DataInstance CurrentDataInstance
    {
        get
        {
            return this.currentDataInstance;
        }
        set
        {
            if ( this.currentDataInstance == value )
                return;
            this.currentDataInstance = value;
            this.OnPropertyChanged( new PropertyChangedEventArgs("CurrentDataInstance"));
        }
    }
    protected virtual void OnPropertyChanged( PropertyChangedEventArgs e )
    {
        if ( this.PropertyChanged != null )
            this.PropertyChanged( this, e );
    }
}