mvvm-light

MVVM light - how to access property in other view model

a 夏天 提交于 2019-12-17 06:11:14
问题 I'm using mvvm light to build a Silverlight application. Is there a code snippet that shows how to access a view model's property or command from within another view model or user control's code behind? I guess it's simple, but I somehow missed something. Ueli 回答1: You could use the Messenger to do this: Send the user in the UserViewModel: Messenger.Send<User>(userInstance); would just send the user to anyone interested. And register a recipient in your CardViewModel: Messenger.Register<User>

Creating an MVVM friendly dialog strategy

筅森魡賤 提交于 2019-12-17 05:48:06
问题 I'm trying to create a strategy for handling popup forms for use throughout any part of my application. My understanding so far is that I will need a single UserControl in the root of my MainWindow. This will be bound to its own ViewModel which will handle the messages that are sent within the app. I'm using MVVM Light, and I'm fairly new to the Messenger class. Imagine a Master/Details scenario, where a list a objects are contained within a ListBox . Selecting one of these items and clicking

How to open a new window using MVVM Light Toolkit

不羁的心 提交于 2019-12-17 04:46:07
问题 I am using MVVM Light toolkit in my WPF application. I would like to know what is the best approach for opening a new window from an existing window. I have got this MainViewModel , which is responsible for MainWindow of my application. Now in the MainView , on a button click, I would like to open a second window on top of it. I have got RelayCommmand binded to the Button 's Command . In the RelayCommand 's method, I can create a new window object and simply call Show() , something like this:

Does mvvm light v3 unregister work properly?

爱⌒轻易说出口 提交于 2019-12-14 02:46:23
问题 Is there a problem with the MvvM-Light v3 unregister? I am registering like this: Messenger.Default.Register<DialogResponse>(this, MessageTypesUI.YesNoQueryResponse, AnswerResponse); Then in "AnswerResponse" Messenger.Default.Unregister<DialogResponse>(MessageTypesUI.YesNoQueryResponse); Both methods execute, and AnswerResponse is called, but the second time it is called twice and the third time thrice, etc. It acts as if my "Unregister" is being ignored. I tried it both with Unregister() and

How can I initialize a property in a viewmodel when creating a new view?

牧云@^-^@ 提交于 2019-12-14 01:28:49
问题 I have an application that opens a view that allows you to search for data. However, in order to to search, the user has to select what category he wants to search under. Currently, I'm trying to figure out how to pass that selected category from the main viewmodel(as an int) to the new search view's view model. Currently I'm trying to use something like this in the main view: Let's say I have two views View1 and View2 an respective viewmodels for each. View2ViewlModel looks like this: public

What is the proper way to use tokens with the Messenger class?

∥☆過路亽.° 提交于 2019-12-14 01:09:59
问题 I am using version 3.0.3.19 of the MVVM Light Toolkit. From http://blog.galasoft.ch/archive/2010/03/16/whatrsquos-new-in-mvvm-light-v3.aspx: Messages can now be sent through the Messenger with a token. To send a message with token, use the method overload Send(TMessage message, object token). To receive a message with token, use the methods Register(object recipient, object token, Action action) or Register(object recipient, object token, bool receiveDerivedMessagesToo, Action action) The

NavigationPage is incremented for each HyperlinkButton click (Silverlight)

情到浓时终转凉″ 提交于 2019-12-13 18:09:06
问题 This is probably one of those questions where the answer really should be too obvious for any to miss. Still, I can't seem to figure out why my "play&learn" application behaves the way it does. On my Mainpage.xaml I have a StackPanel containing several HyperlinkButtons which navigates to a set of NavigationPages . There is also a NavigationFrame with a UriMapper to hold the "pages". <StackPanel Background="Black" Orientation="Horizontal" Grid.Row="0"> <HyperlinkButton Name="Home" TargetName=

XAML designer “Could not load file or assembly Autofac 4.1” in App.xaml of UWP application using MVVMLight

只谈情不闲聊 提交于 2019-12-13 17:31:17
问题 Starting with a blank Universal Windows Application I added Autofac 4.1, Autofac.Extras.CommonServiceLocator 4.0 and MvvmLightLibs 5.3. I then created the following ViewModelLocator class. using Autofac; using Autofac.Extras.CommonServiceLocator; using GalaSoft.MvvmLight.Views; using Microsoft.Practices.ServiceLocation; namespace UwpTest { public class ViewModelLocator { public static IContainer Container { get; private set; } public static bool IsBuilt { get; set; } public ViewModelLocator()

Pass UIElement to CommandParameter

自作多情 提交于 2019-12-13 14:27:51
问题 I'm using MVVM Light in my WPF application. I created a class RedirectToUriCommandArgument.cs . public class RedirectToUriCommandArgument : DependencyObject { #region Properties public static readonly DependencyProperty PageProperty = DependencyProperty.Register(nameof(Page), typeof(object), typeof(RedirectToUriCommandArgument), new UIPropertyMetadata(null)); public object Page { get => (object)GetValue(PageProperty); set => SetValue(PageProperty, value); } public string Uri { get; set; }

How to update gui in c# wpf from asynchronous method callback

耗尽温柔 提交于 2019-12-13 09:58:25
问题 I've search on stackoverflow and also in net and I couldn't find solution to my problem. I read from a stream in async way. I want callback to update gui [STAThread] private void ClientLoggedCallback(IAsyncResult res) { try { MailClient.Helpers.Client.getInstance().client.GetStream().EndWrite(res); MailClient.Helpers.Client.getInstance().asyncRecieveEncryptedProtocolMessage(new AsyncCallback(LoginInfo_recieved)); } catch { } } [STAThread] private void LoginInfo_recieved(IAsyncResult res) {