1
나는 복합 MVVM 응용 프로그램 작업 및 글로벌 바인딩 이벤트가 발생 얻기 위해 노력하고 있어요! - 그렇지 않은 경우를 제외하고 ..복합 명령어가 작동하지
CanRun가 true를 반환하지만 버튼이 기본적으로 사용할 수 없습니다! !! !! Composite Guide를 따라 왔고 OnLoadMenu가 실행되지 않습니다 !!!
저는 서클 (Event Aggregators, DelegateCommands, Composite Commands)에서 돌아 다니고 있습니다. 그냥 작동하지 않습니다. 어떤 사람이 이것을보고 내가 무엇을 놓쳤는 지 말해 줄 수 있습니까 ?? 당신이 참에 CompositeCommand
monitorCommandActivity
와 세트를 만드는 경우 PRISM을 사용하는 경우
//xmlns:local="clr-namespace:Commands;assembly=MyApp"
<Button HorizontalAlignment="Center" Margin="1,1,1,1"
Grid.Row="2"
Command="{x:Static local:AdminGlobalCommands.LoadAdminMenu}"/>
public static class AdminGlobalCommands // In Common Code Library
{
//List All Global Commands Here
public static CompositeCommand LoadAdminMenu = new CompositeCommand();
}
public class AdminModuleViewModel : ViewModelBase, IAdminModuleViewModel // In AdminModule
{
protected IRegionManager _regionManager;
private IUnityContainer _container;
public AdminModuleViewModel(
IEventAggregator eventAggregator,
IBusyService busyService,
IUnityContainer container,
IRegionManager regionManager
)
: base(eventAggregator, busyService, container)
{
// show the progress indicator
busyService.ShowBusy();
this._regionManager = regionManager;
this._container = container;
//set up the command receivers
this.AdminShowMenuCommand = new DelegateCommand<object>(this.OnLoadAdminMenu, this.CanShowAdminMenu);
//Listen To Events
AdminGlobalCommands.LoadAdminMenu.RegisterCommand(AdminShowMenuCommand);
busyService.HideBusy();
}
public DelegateCommand<object> AdminShowMenuCommand { get; private set; }
private bool CanShowAdminMenu(object obj)
{ //Rules to Handle the Truth
return true;
}
public void OnLoadAdminMenu(object obj)
{
UIElement viewToOpen = (UIElement)_container.Resolve(typeof(AdminMenuControl)) ;
_regionManager.AddToRegion("MainRegion", viewToOpen);
_regionManager.Regions["MainRegion"].Activate(viewToOpen); ;
}
}
AdminModuleViewModel은 어디에 구성되어 있습니까? DataContext에 어떻게 설정되고 있습니까? 또한 명령의 "global-ness"가 필요한지 아니면이 Button 객체 명령을 ViewModel의 핸들러에 연결하려고합니까? 그렇다면 더 쉬운 방법을 게시 할 수 있습니다. –
프리즘 해결을 통해 데이터 컨텍스트가 설정되었습니다 ...이 예제에서는이 모듈에서 명령을 실행하고 싶습니다. 예를 들어 복합체이며 셸은 AdminModule에 대해 알지 못하므로 기본 응용 프로그램에 넣을 수 없으므로 Globl 명령 클래스에 넣을 수 있습니다. (전역 명령 클래스는 응용 프로그램 인프라에 있으며 응용 프로그램 모듈을 "인식"하지 않습니다. 명령이 응용 프로그램의 어느 위치에서든 트리거되면 관리 모듈에서 확인하려고합니다. 메뉴가 표시됩니다. – Traci