mvvm-light

Set the DataContext of a ViewModel in MVVMLight

北城以北 提交于 2020-01-06 20:14:58
问题 I've got a question of the MVVM-Pattern. So I'm not sure, that I've had understand it completely. My scenario: ViewModelLocator : Provide the requested ViewModel to a specified view. LoginViewModel: ViewModel for the LoginView MainPageViewModel: ViewModel for the MainPageView My example app. is simple: The user can login and comes to the MainPageView. The MainPageView uses the MainPageViewModel. I use the messenger of the MVVMLight framework to navigate from the LoginView to the MainPageView.

Use RelayCommand with not only buttons

佐手、 提交于 2020-01-06 17:59:51
问题 I am using MVVM Light in my project and I am wondering if there is any way to use RelayCommand with all controls (ListView or Grid, for example). Here is my current code: private void Item_Tapped(object sender, TappedRoutedEventArgs e) { var currentItem = (TechItem)GridControl.SelectedItem; if(currentItem != null) Frame.Navigate(typeof(TechItem), currentItem); } I want to move this code to Model and use RelayCommand, but the ListView, Grid and other controls don't have Command and

MVVMLight within another MVVMLight project

巧了我就是萌 提交于 2020-01-06 08:37:07
问题 I am working on a MVVMLight / WPF project and need to add a chunk of functionality which will include multiple views and viewmodels. I know this same bit of functionality will be used in other projects in the near future so I would like to make this functionality its own project that I can add to other solutions as needed wiuth little or no modification. I started by adding a second MVVMLight project (Beta), removing the standard MainWindow.xaml and MainViewModel.cs files and created a simple

MvvmLightLibsStd10 and UWP

空扰寡人 提交于 2020-01-06 05:06:30
问题 How can you create a binding between a ViewModel and a View? In the past there was a Locater created in App.xaml and then on the view you had this: DataContext="{Binding MainViewModel, Source={StaticResource ViewModelLLocator}}" I can't even click in the Properties of the View and then create DataContext binding. 回答1: In recent versions of MVVM light they changed how ViewModelLocator works due to it taking a dependency on Microsoft.Practices.ServiceLocation and the former not being .NET

MvvmLight print message to debug

女生的网名这么多〃 提交于 2020-01-06 03:52:17
问题 Is there a simple way to print all Messenger.Default.Send() to debug? Don't want to override them. 回答1: Create a function in an abstract ViewModel that everyone inherits from, which uses a define or global variable to determine if it debugs as well/instead. This could also be if you're running as Debug or Release. public abstract BaseViewModel public SendMessage() { if(DEBUG) // The global variable, or definition, or current run type - whatever Debug.WriteLine(); // else // Commented if you

Messaging problem using MVVM-Light

六月ゝ 毕业季﹏ 提交于 2020-01-06 03:32:26
问题 Initially I wanted to pass an "ObservableCollection< customClass>" between two VMs , but even simple messaging isn't working for me. MainViewModel private void openNewSpecialCustomer() { GalaSoft.MvvmLight.Messaging.Messenger.Default.Send("Musaab"); Console.WriteLine("send done"); AddNewSpecialCustomer a = new AddNewSpecialCustomer(); _dialogService.showDialoge(a); } AddNewSpecialCustomerViewModel public AddNewSpecialCustomerViewModel() { GalaSoft.MvvmLight.Messaging.Messenger.Default

Dynamic Row and Column Creation using WPF and MVVM

*爱你&永不变心* 提交于 2020-01-05 04:41:11
问题 Note: I'm using MVVM Light Toolkit and MahApps.Metro . I've checked the answers but it doesn't seem like any of them relate to my question. I have a Grid whose columns and header should be dynamically created. The number and value of columns is unknown to view, and the number of rows is unknown to view. Columns, rows and data in the rows represent a Database Table. All data is present in the ViewModel. I have an ObservableCollection<ServerRow> ServerRows; in my ViewModel. Server Row object is

WPF MVVM Shared Data Source

点点圈 提交于 2020-01-05 02:01:09
问题 I have been tasked with a new project. I am familiar with WPF and mvvm and have completed a few in production projects utilizing it. This latest request is simple – but requires sharing an incoming datasource (that is refreshed every 30 seconds) between two views. Here are a few of the ways I have thought of achieving this: 1) Create one shared view model between the two views. I don’t really like this option – while they do use the same data source, what the two views do with the data is

Using ListPicker and DataBinding

放肆的年华 提交于 2020-01-04 19:42:20
问题 Ok. I give up. I want to use ListPicker control in one of my Windows Phone apps. I am getting an Exception SelectedItem must always be set to a valid value . This is my XAML piece of ListPicker: <toolkit:ListPicker x:Name="CategoryPicker" FullModeItemTemplate="{StaticResource CategoryPickerFullModeItemTemplate}" Margin="12,0,0,0" ItemsSource="{Binding CategoryList}" SelectedItem="{Binding SelectedCategory, Mode=TwoWay}" ExpansionMode="ExpansionAllowed" FullModeHeader="Pick Categories"

WP8.1 back button quits the app

天涯浪子 提交于 2020-01-04 16:57:08
问题 The last time I developed against Windows Phone, it was with version 8. Now I'm making use of 8.1. Maybe this is a new feature from MS, but when I press the back button on the phone, regardless of how deep I'm into the app, the app minimizes. This is seriously annoying! Is there anything that I can do? Many thanks in advance! Kind regards, 回答1: Yes, this is the normal behaviour in Windows Phne 8.1 non-SL apps. Here a workaround to implement in your App.xaml.cs file: public App() { this