【问题标题】:Get ViewModel data using MEFedMVVM使用 MEFedMVVM 获取 ViewModel 数据
【发布时间】:2012-07-02 11:51:25
【问题描述】:

我目前正在使用 MEFedMVVM 框架来访问 ViewModel,并想知道如何从当前正在使用的另一个 ViewModel 获取数据。这与 Cinch 的使用相结合。

目前我的标签控件定义如下:

<Window.Resources>


    <DataTemplate DataType="{x:Type CinchV2:WorkspaceData}">
        <AdornerDecorator>
            <Border HorizontalAlignment="Stretch" 
                VerticalAlignment="Stretch" 
                CinchV2:NavProps.ViewCreator="{Binding}"/>
        </AdornerDecorator>
    </DataTemplate>


</Window.Resources>

一旦加载了视图,我的主窗口 ViewModel 就会按以下方式设置:

private void ViewAwareStatusService_ViewLoaded()
    {

        if (Designer.IsInDesignMode)
            return;

        //String imagePath = ConfigurationManager.AppSettings["YourImagePath"].ToString();

        WorkspaceData loginWorkSpace = new WorkspaceData(null, "LoginUserControl", null, "Login", true);
        WorkspaceData aboutWorkspace = new WorkspaceData(null, "About", null, "About", true);
        WorkspaceData viewAlbumsWorkspace = new WorkspaceData(null, "ViewAlbums", null, "View Albums", true);
        WorkspaceData readReviewSelectWorkspace = new WorkspaceData(null, "ReadReviewsSelect", null, "Select Review", true);
        WorkspaceData adminWorkspace = new WorkspaceData(null, "Admin", null, "Admin", true);

        Views.Add(aboutWorkspace);
        Views.Add(loginWorkSpace);
        Views.Add(readReviewSelectWorkspace);
        Views.Add(viewAlbumsWorkspace);


        SetActiveWorkspace(aboutWorkspace);

        UserName = new DataWrapper<string>(this, UserNameChangeArgs);
        UserName.IsEditable = true;
        //UserName.DataValue = ConfigurationManager.AppSettings["UserName"];

        UserRole = new DataWrapper<string>(this, UserNameChangeArgs);
        UserRole.IsEditable = true;
        //UserRole.DataValue = ConfigurationManager.AppSettings["UserType"];
    }

MainWindow ViewModel 继承 ViewModelBase 类,其配置如下(Cinch 类):

namespace Cinch
{
public abstract class ViewModelBase : INotifyPropertyChanged, ICinchDisposable,  IParentablePropertyExposer
{
    public ViewModelBase();

    public SimpleCommand<object, object> CloseActivePopUpCommand { get; }
    public SimpleCommand<object, object> CloseWorkSpaceCommand { get; }
    public string DisplayName { get; set; }
    public bool IsCloseable { get; set; }
    protected virtual bool ThrowOnInvalidPropertyName { get; }
    public ObservableCollection<WorkspaceData> Views { get; set; }

    public event EventHandler<EventArgs> ActivateRequest;
    public event EventHandler<CloseRequestEventArgs> CloseRequest;
    public event EventHandler<EventArgs> CloseWorkSpace;
    public event Action<string> FocusRequested;
    public event PropertyChangedEventHandler PropertyChanged;

    public void Dispose();
    public Delegate[] GetINPCSubscribers();
    protected void NotifyPropertyChanged(PropertyChangedEventArgs args);
    protected void NotifyPropertyChanged(string propertyName);
    protected virtual void OnDispose();
    public virtual void RaiseActivateRequest();
    public virtual void RaiseCloseRequest(bool? dialogResult);
    public void RaiseFocusEvent(string focusProperty);
    public void SetActiveWorkspace(WorkspaceData viewnav);
    [DebuggerStepThrough]
    [Conditional("DEBUG")]
    public void VerifyPropertyName(string propertyName);
}

现在我想要做的是,通过在 loginWorkspace 中单击一个按钮,该按钮是一个带有 ViewModel 的 UserControl,将 Admin 选项卡从 LoginViewModel 添加到 MainWindow 的 Views ObservableCollection。

【问题讨论】:

    标签: c# wpf cinch mefedmvvm


    【解决方案1】:

    阅读有关使用调解器的信息。您可以从您的 loginviewmodel 发送消息。然后让 mainwindowview 模型可以监听相应的消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      相关资源
      最近更新 更多