이 나의 주, 부모 클래스, 뷰 모델입니다 :Caliburn.Micro : 지휘자가있는 페이지 간 이동 : 하위 클래스에서 부모 클래스 메서드 또는 속성을 호출하려면 어떻게해야합니까?
[AutofacRegisterType(PAGE_NAME, typeof(IMainPage), IsSingleInstance = false)]
public class MainPageViewModel : MainPageViewModelBase
{
public const string PAGE_NAME = "MainPage";
public MainPageChildsConductor ChildPages { get; private set; }
public IMainPageChild ActiveChildPage
{
get { return ChildPages.ActiveItem; }
}
public MainPageViewModel()
{
PageName = PAGE_NAME;
DisplayName = PAGE_NAME;
DisposeOnDeactivate = true;
InitChildPages();
}
private void InitChildPages()
{
ChildPages = new MainPageChildsConductor();
ChildPages.Parent = this;
ChildPages.ConductWith(this);
var trallchilds = TypeRegistry.GetItemsByType<IMainPageChild>();
var trchilds = trallchilds.Where(p => p.AutoRegister != null && p.AutoRegister.Name.StartsWith(PAGE_NAME + ":")).ToList();
var childs = new List<IMainPageChild>();
foreach (var trchild in trchilds)
{
var child = trchild.CreateType<IMainPageChild>();
childs.Add(child);
}
childs.Sort((a, b) => a.PageIndex.CompareTo(b.PageIndex));
ChildPages.Items.AddRange(childs);
ChildPages.ActivateWith(this);
ChildPages.DeactivateWith(this);
}
}
이, 뷰 모델 내 자식 클래스 중 하나입니다
[AutofacRegisterType(PAGE_NAME, typeof(IMainPageChild), IsSingleInstance = false)]
public class Child1PageViewModel : MainPageChildViewModelBase
{
public const string PAGE_NAME = "ChildPage:Child1Page";
public const int PAGE_INDEX = 30;
public Child1PageViewModel()
{
PageName = PAGE_NAME;
DisplayName = "Child1";
PageIndex = PAGE_INDEX;
InitButtons();
InitSummaryData();
}
}
을 그리고 이것은 Caliburn.Micro 클래스 지휘자를 상속하는 클래스입니다 :
public class MainPageChildsConductor : Conductor<IMainPageChild>.Collection.OneActive
{
public MainPageChildsConductor()
{
}
public override void NotifyOfPropertyChange([CallerMemberName] string propertyName = null)
{
base.NotifyOfPropertyChange(propertyName);
if (Parent is INotifyPropertyChangedEx)
((INotifyPropertyChangedEx)Parent).Refresh();
}
}
질문은 : 나는 자식 페이지 'Child1PageViewMode에서 상위 페이지'MainPageViewModel '에 존재하는 메서드 또는 속성을 호출하는 방법 엘'???
는 나는이 같은 부모 클래스에서 하위 클래스에 존재하는 메서드 또는 속성을 호출 할 수있는 방법을 알고 : 경우 (ActiveChildPage.PageName == "ChildPage : Child1Page") { \t (페이지입니다. ChildrenPageTabs.Child1PageViewModel) ActiveChildPage) .DoShowClickedButton(); } 하지만 다른 방법으로는 어떻게해야할지 모르겠다 - 자식 클래스의 부모 클래스에있는 메서드 나 속성을 호출하는 방법은 무엇입니까? 아무도 내가 어떻게 할 수 있을지 아무 생각이 없니? – Navuhodonosor
부모 클래스는 자식 클래스에 자신을 제공합니다. – Will
자녀보기 모델이 Screen에서 상속 받거나 IScreen을 구현합니까? 이는 하위 뷰 모델에서 필요하며 활성화 된 경우에만 사용할 수 있습니다. 자세한 내용은 http://stackoverflow.com/questions/16832780/caliburn-micro-ichild-parent-is-null-unless-activated-by-conductor를 참조하십시오. –