private void CreateDataBindings(HexExplorerViewModel viewModel) { m_FileTabCtrl.TabPages.BindToObservableCollection(viewModel.AllOpenFiles, (avm) => CreateNewTabPage(avm)); m_FileTabCtrl.DataBindings.Add(new Binding(nameof(m_FileTabCtrl.SelectedIndex), viewModel, nameof(viewModel.ActiveFileIndex), true, DataSourceUpdateMode.OnPropertyChanged)); }
public HexExplorerView(int viewId, MessageManager msgMgr) : base(viewId, "Hex Explorer", msgMgr) { m_ExplorerVm = new HexExplorerViewModel(viewId, msgMgr); m_OpenFileCmd = new RelayCommand <string>((filePath) => LoadFileAction(filePath), true); m_CloseTabsToRightCmd = new RelayCommand <int>( (param) => { // if we're removing everything to the right, the AllOpenFiles // Count value will change. we'll just wait until that Count property // is one above our target tab (since that'd be the theoretic last tab). int targetCount = param + 1; while (m_ExplorerVm.AllOpenFiles.Count > targetCount) { CloseTabAction(param + 1); } }, false); m_CloseTabsToLeftCmd = new RelayCommand <int>( (param) => { for (int i = param - 1; i >= 0; --i) { CloseTabAction(i); } // set the active tab index to 0. the tab changed // event doesn't seem to be getting called. it hasn't // crashed yet, but that seems like it'd be in a bad state. m_ExplorerVm.ChangeActiveIndexCommand.Execute(0); }, false); // this will be passed either a tab index or a view model. // need to differentiate on the fly when we're called. m_CloseTabCmd = new RelayCommand <object>( (param) => { int?iParm = param as int?; if (iParm.HasValue) { CloseTabAction(iParm.Value); } else { var evm = param as HexExplorerViewModel; System.Diagnostics.Debug.Assert(evm != null); CloseTabAction(evm.ActiveFileIndex); } }, false ); InitializeComponent(); CreateDataBindings(m_ExplorerVm); SubscribeToMessageType(MessageType.FileAssembled, m_OpenFileCmd); }