private static Page CreatePage(object viewModel) { var view = EnsurePage(viewModel, PiracRunner.GetViewForViewModel(viewModel)); view.DataContext = viewModel; return(view); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Initialize data generator Randomizer.Seed = new Random(24601); PiracRunner.Start <MainWindowViewModel>(new PiracContext { Container = new AutofacContainer() }); }
private static Window CreateWindow(object viewModel, bool isDialog) { var view = EnsureWindow(PiracRunner.GetViewForViewModel(viewModel), isDialog); ViewModelBinder.Bind(view, viewModel); var screen = viewModel as IObserveActivation; if (screen != null) { new WindowConductor(screen, view); } return(view); }
private static bool TryBind(FrameworkElement element, PropertyInfo property, object viewModel) { // Unlike Caliburn.Micro we only name bind to certain control types. // - ContentControl // - ItemsControl var contentControl = element as ContentControl; if (contentControl != null && contentControl.Content == null) { Log.Info($"Binding ContentControl {contentControl.Name} to property {property.Name}"); var contentViewModel = property.GetValue(viewModel, null); if (contentViewModel != null) { var contentView = (FrameworkElement)PiracRunner.GetViewForViewModel(contentViewModel); Bind(contentView, contentViewModel); contentControl.Content = contentView; return(true); } } var itemsControl = element as ItemsControl; if (itemsControl != null) { Log.Info($"Binding ItemsControl {itemsControl.Name} to property {property.Name}"); var itemViewModel = property.GetValue(viewModel, null) as IEnumerable; if (itemViewModel != null) { var itemViews = itemViewModel.OfType <object>().Select(vm => { var view = (FrameworkElement)PiracRunner.GetViewForViewModel(vm); Bind(view, vm); return(view); }) .ToList(); itemsControl.ItemsSource = itemViews; return(true); } } return(false); }