prism

Prism, connecting Views and ViewModels with Unity, trying to understand it

こ雲淡風輕ζ 提交于 2019-12-20 12:28:36
问题 Creating the View and View Model Using Unity Using Unity as your dependency injection container is similar to using MEF, and both property-based and constructor-based injection are supported. The principal difference is that the types are typically not implicitly discovered at run time; instead, they have to be registered with the container. Typically, you define an interface on the view model so the view model's specific concrete type can be decoupled from the view. For example, the view can

WPF/Prism: What is a UNITY Container?

时间秒杀一切 提交于 2019-12-20 08:18:21
问题 Can someone please explain to me the notion of a Unity Container like I'm a 6 year old kid? How does it work and what does it do? 回答1: This is a more technical description of the background, I hope you still find it useful. Generally put, it is a DI (dependency injection) container. Given the following class: public class Sample { Service a; public Sample() { a = new Service(); } } The problem with that is that it initializes its own version of Service , making it very hard to adjust for code

How to register regions inside user controls or control templates in RegionManager?

烂漫一生 提交于 2019-12-20 07:22:38
问题 I am using IRegionManager to load and navigate to views, I have no problem loading content to my main region in my main view which is loaded with my bootstrapper class but I cant load content to regions inside my loaded views, the region manager does not seem to be registering these regions. my bootstrapper class: protected override DependencyObject CreateShell() { return this.Container.Resolve<MainWindowView>(); } protected override void InitializeShell() { Application.Current.MainWindow

Maintaining the collection in a List/ObservableCollection

断了今生、忘了曾经 提交于 2019-12-20 06:34:34
问题 i have been successfully adding an item to list in a MVVM, and now my problem is maintaining the list in the view model. Every time i navigate to a page or go back to a page and return to that listview, the list resets. how will i able to achieve that? i am currently using the prism to build the MVVM. The ViewModel: public ObservableCollection<CartData> _cartData; public ObservableCollection<CartData> CartData { get { return _cartData; } set { SetProperty(ref _cartData, value); } } private

Pass data parameter from model to next page Prism Xamarin Forms

安稳与你 提交于 2019-12-20 06:24:52
问题 I need to pass data from ViewModel 1 to ViewModel 2 using Prism. TodoItem is my Model with the string: public TodoItem _todotItem { get; set; } private readonly INavigationService _navigationService; I assigned it in the constructor: public MainPageViewModel(INavigationService navigationService, TodoItem todotItem) { _navigationService = navigationService; _todotItem = todotItem; } And this is the code I use to navigate to next page (including the parameter): NavigationParameters navParams =

EventToCommandBehavior not found in xmlns clr-namespace:Prism.Behaviors

老子叫甜甜 提交于 2019-12-20 04:19:42
问题 I'm working on Xamarin.Forms project. Before Prism 6.3 I used 6.2 with Corcav.Behaviors package. I didn't need to pass parameters, so it worked good. But, in iOS project in AppDelegate I needed to run this line: Corcav.Behaviors.Infrastructure.Init(); I had a comment: //Added to prevent iOS linker to strip behaviors assembly out of deployed package. Now EventToCommand was added to 6.3 version, so I uninstalled Corcav.Behaviors package and implemented simple example. In Android everything

Prism 6.1 ViewModelLocator doesn't instantiate my ViewModel

廉价感情. 提交于 2019-12-20 03:52:37
问题 I just set up a new project recently, using Prism 6.1(with Unity). I've my bootstrapper: public class ServerBootstrapper : UnityBootstrapper { protected override DependencyObject CreateShell() { return Container.Resolve<MainShell>(); } protected override void InitializeShell() { base.InitializeShell(); Application.Current.MainWindow = (Window)Shell; Application.Current.MainWindow.Show(); } protected override void ConfigureModuleCatalog() { base.ConfigureModuleCatalog(); ModuleCatalog catalog

Prism - EventAggregator.GetEvent<>.Subscribe() - Using Generics & Contraints

爷,独闯天下 提交于 2019-12-20 03:35:23
问题 I am having an issue subscribing to events with the event Aggregator that comes as part of the prism framework. If I use something such as eventAggregator.GetEvent<string>().Subscribe(MyMethod) then it all works ok, my method fires when an event has been published. However, when moving to a more complex object other than I string I run into problems. I have a bunch of classes that all derive from an Interface (IRequest) for example I have my event class setup as follows public class MyEvent

Cannot find Region in RegionManager (using PRISM)

戏子无情 提交于 2019-12-20 01:38:14
问题 I'm writing an application in Prism. I have a user control and contains two <ContentControl> controls. These both have Regions assigned to them. The usercontrol is being hosted in a Window that is being shown using ShowDialog() . I'm adding the one of my views to a region using view discovery and the other I want to inject the view into its region. The view discovery works fine. However when I try and reference the other region to inject the view I get the exception: KeyNotFoundException The

Mocking an IoC Container?

ぐ巨炮叔叔 提交于 2019-12-19 10:21:05
问题 Does it make sense to mock an IoC container? If so how would I go about it, using Moq? I am creating a Prism 4 app, using Unity 2.0 as the IoC container. I inject the container into classes that need its services, rather than using Prism's ServiceLocator . For unit testing, unless I need other Prism services for my test, I simply instantiate the container and register mocks with it. I pass the container to the class under test, which resolves the mocks. It's all fairly simple, but I am