PRISM4 MVVM Pattern을 사용하고 있으며 뷰가 성공적으로로드되어 응용 프로그램이 시작될 때 해당 영역에 표시됩니다. 응용 프로그램이 시작되면 뷰가로드 될 때 ViewModels이 자동으로 초기화됩니다. 그러나 새 탭 (새 영역)에 새 뷰를 주입하려고하면 새 뷰의 ViewModel이 초기화되지 않습니다. 다음 뷰 주입에 대한 코드입니다 :ViewModel이 뷰 삽입 (WPF PRISM 4 MVVM)에서 초기화되지 않았습니다.
이IRegion region = regionManager.Regions["RegionNameGoesHere"];
var pane = new Views.ABCView() {Tag = id};
regionManager.Regions["RegionNameGoesHere"].Add(pane);
위의 코드는 새 탭을 열고 새보기를로드는 있지만 뷰 모델을 초기화하지 않습니다. 컨트롤의 각 탭은 새로운 영역입니다 (탭 컨트롤을위한 RegionAdapter가 있습니다).
다음은 비하인드 코드입니다 :
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Docking;
namespace Company.Application.Module.Assembly.Views
{
[Infrastructure.Behaviours.ViewExport("ABCView")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public partial class ABCView : RadPane
{
public ABCView()
{
this.InitializeComponent();
}
/// <summary>
/// Sets the ViewModel.
/// </summary>
/// <remarks>
/// This set-only property is annotated with the <see cref="ImportAttribute"/> so it is injected by MEF with
/// the appropriate view model.
/// </remarks>
[Import]
[SuppressMessage("Microsoft.Design", "CA1044:PropertiesShouldNotBeWriteOnly", Justification = "Needs to be a property to be composed by MEF")]
ABCViewModel ViewModel
{
set
{
this.Decorator.DataContext = value;
//this.DataContext = value;
}
}
}
}
그리고 여기에 몇 가지 속성과 이벤트로 뷰 모델을합니다. 위의 코드에서 ViewModel을 초기화하기 위해 뭔가 빠졌습니다. 어떤 제안이라도 대단히 감사하겠습니다.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel.Composition;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Xml;
using System.Xml.XPath;
using System.Windows.Data;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.ViewModel;
namespace Company.Application.Module.Assembly.Views
{
[Export(typeof(ABCViewModel))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class ABCViewModel : NotificationObject
{
private readonly IRegionManager regionManager;
[ImportingConstructor]
public ABCViewModel(IRegionManager regionManager)
{
// Event Aggregator
//this.eventAggregator = eventAggregator;
// Region Manager
this.regionManager = regionManager;
}
#region P R O P E R T I E S
#region E V E N T S
}
}
다니엘 감사합니다. 몇 가지 연구를 할 것이고, 해결책을 찾으면 여기에 게시 할 것입니다. 건데 –
솔루션을 찾았습니까? – JohnC
@JohnC 누군가가 당신의 코멘트를 볼 가능성이 높아지게하려면, 당신의 코멘트로 그들의 이름 앞에 @를 넣으십시오. –