mvvm-light

How to Register Multiple Interface Implementation In IoC in MvvmLight?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:27:56
问题 Register Multiple Interface Implementation In LightInject IoC How to use MvvmLight's Ioc to solve the problem? I have multiple DataService (DataService1, DataService2, DataService3 ...). They are all IDataService and need to be contacted with multiple ViewModel. Mvvmlight can't do it: SimpleIoc.Default.Register<IDataService, DataService1>("DataService1Key"); SimpleIoc.Default.Register<IDataService, DataService2>("DataService2Key"); ... 回答1: You can also use 'class' key identifiers in

View state remains the same when a new ViewModel instance is created MVVM

情到浓时终转凉″ 提交于 2019-12-12 02:50:10
问题 I'm sure the answer to this is already out there just can't seem to find it. I have a SubView which I am dynamically in the the MainViewModel. This is then displayed to the user using a style. When I create a new instance of the SubViewModel the View is not recreated if it of the same type as it was before. This is an issue as the selected tab remains the same and is not reset to the first tab. Although I could just save the selected tab index in the ViewModel to reset it I feel it is purely

MenuBarItems in MVVM

独自空忆成欢 提交于 2019-12-12 02:19:01
问题 I am playing with mvvm and wpf. Now, my total solution is MVVM-friendly. The only thing i have put in code behind is the "make new product" & close buttons on the mainview. Now im adding a menubar, and i was wondering if i can put these "make new product" & close Items in code behind, or is this a no go? Thanks in advance. 回答1: The MVVM way to do it is commands. You can consider them as proxies between your declarative XAML and imperative VM. Create CreateNewProductCommand, implementing

Silverlight 4 Combobox with selectedValue using MVVM-Light

北城余情 提交于 2019-12-11 23:09:49
问题 I have recently started using the MVVM-Light toolkit and I am stuck on the following problem: I have a basic Silverlight Combobox that is bound to a viewmodel with an ObservableCollection of type MyUser. The Combobox implements a custom DataTemplate to combine the user’s name and surname. After loading the list of users, how do I set the Combobox to select the first user in the list and display this selected user in the collapsed Combobox? I know that it has been suggested to use the

can anyone think of why using this particular class in a design time data source will break all design time bindings?

微笑、不失礼 提交于 2019-12-11 19:23:23
问题 I generated this class using SQLMetal.exe. It is very bindable at runtime, but if I use this class at design time, all of my design time blend bindings are busted. I am using the MVVM-Light framework and I am building an app for WP7. If I extract an interface for this class, and create a simple POCO that implements this interface and I use my simple poco in my design time data source, all of the bindings come alive. Here is the class that was generated by SQLMetal.exe. [Table(Name=

EventToCommand not working when migrate to v4 for SL5

纵然是瞬间 提交于 2019-12-11 19:20:05
问题 I have SL4 app with MVVMLight. I migrate it to SL 5 and got following error when compiling the app: The tag 'EventToCommand' does not exist in XML namespace 'clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.SL5 The xaml for this error is: xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.SL5" <i:Interaction.Triggers> <i:EventTrigger EventName=

how to inject service to view Model in mvvm light

泪湿孤枕 提交于 2019-12-11 19:06:54
问题 I try to use dependency injection to inject service into view model. try this code ViewModelLocator public class ViewModelLocator { public static MainViewModel _main; static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); SimpleIoc.Default.Register<IAccountService, AccountService>(); SimpleIoc.Default.Register<MainViewModel>(); SimpleIoc.Default.Register<LoginViewModel>(); } /// <summary> /// Gets the Main property. /// </summary> [System.Diagnostics

UWP / MVVMlight : Replacing Obsolete ServiceLocator and SimpleIoc Register

只谈情不闲聊 提交于 2019-12-11 17:45:31
问题 I open this topic again. I face a probelm when I update my UWP app: I'm gonna give more detail: Here is my old code before update running perfectly on UWP/Win10 10240 in my app.xaml <Application.Resources> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </Application.Resources> in my App.xaml.cs public class ViewModelLocator { public const string MainMenuPageKey = "MainMenuPage"; public const string QuestionPageKey = "QuestionPage"; static ViewModelLocator() { ServiceLocator

WPF XAML listbox selected item border color

走远了吗. 提交于 2019-12-11 17:28:54
问题 I have implemented some listbox which contains border and a grid in this border. <Style x:Key="SelectedHiglightStyle" TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource MaterialDesignListBoxItem}"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /> </Style.Resources> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter

Getting result from ShowDialog without resorting to code behind

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 17:26:28
问题 I'm implementing code from the excellent answer to this question WPF + Castle Windsor + MVVM: Locator-DataContext. I'm not sure how to get the value from ShowDialog() though without resorting to code behind (which breaks testability), anyone have any ideas? I was using this class with the MVVM Light Messenger class and it was working fine, but entails using the Service Locator anti-pattern. EDIT The current code I have that isn't working is DataSourcePicker.xaml.cs public DataSourcePicker