Click here to Skip to main content
15,888,521 members
Everything / MVVM

MVVM

MVVM

Great Reads

by Sacha Barber
It would probably be like Cinch, an MVVM framework for WPF.
by Alan Beasley
Explanation and examples of Additional Templates and Generated Content of a ListBox. Covering Layout, Transitions, and Animation.
by Nish Nishant
An ExifReader class in C# that supports custom formatting and extraction. StyleCop compliant code, with demos for WPF and Windows Forms.
by defwebserver
How using the Silverlight DataTrigger allows you to run a process and then raise another when using View Model (MVVM)

Latest Articles

by Peter Sun (247)
Implement ChatGPT API in C# WPF with GPT3.5-turbo
by Federico Alterio
Description of a library that allows to use a porting of Angular Signals in .NET MVVM Frameworks
by Graeme_Grant
MVVM made simple via Blazing.Mvvm Library using the Microsoft Community Toolkit
by Jo_vb.net
How to get started using the MVVM Toolkit

All Articles

Sort by Updated

MVVM 

16 Feb 2024 by Peter Sun (247)
Implement ChatGPT API in C# WPF with GPT3.5-turbo
26 Dec 2023 by Federico Alterio
Description of a library that allows to use a porting of Angular Signals in .NET MVVM Frameworks
20 Nov 2023 by Graeme_Grant
One method could be using the MVVM Community Toolkit Messenger: Messenger - Community Toolkits for .NET | Microsoft Learn[^] - This allows for loosely coupled communication.
20 Nov 2023 by Graeme_Grant
MVVM made simple via Blazing.Mvvm Library using the Microsoft Community Toolkit
20 Nov 2023 by Member 10371658
I am working with MVVM and i want to set the focus to textbox or button from popup window(Flyout) to parent windows using MVVM and WPF, i tried a lot, but not able to find any solution. parent and child form is a User Control, and on a parent...
23 Oct 2023 by Jo_vb.net
How to get started using the MVVM Toolkit
19 Oct 2023 by Member 10371658
I have a XAML form in MVVM, and there are some textbox and button controls, and I set the TabIndex property for that control, but when I click on tab button from keyboard, it's going to control according to tabindex set. Please help how to set...
18 Oct 2023 by Graeme_Grant
MVVM has nothing to do with the Tab order of controls. TabIndex sets the tab order when the Tab key is pressed. If you want a different Tabbing order, then change the TabIndex to the order that you want.
10 Jul 2023 by A Belal
paid and remain Amount always saved null in database although i get value is not null by javascript What I have tried: my storedProcedure USE [OnlineMarket] GO /****** Object: StoredProcedure [dbo].[InsertintoSalesInvoice] Script Date:...
10 Jul 2023 by Graeme_Grant
This is your 5th question posted. At least put some effort in and learn to format your code so we can at least read it. I have done that for you. If you want help, and for us to read your code, take pride in what you post, it will show. Click on...
23 May 2023 by Graeme_Grant
hmmm... a quick google search: wpf listview search mvvm example - Google[^] turns up many examples, like: List Filtering in WPF with M-V-VM[^], whilst a ListBox is used, the same principle applies. If you are not happy with this, there are many...
23 May 2023 by Jose Castillo
When I press a button I want to search a listview and have it scroll and display the found item Simplifying the WPF ListView by Using the ViewModel Pattern What I have tried: I have not found any examples that can help me
3 May 2023 by Graeme_Grant
You asked about IValueConverter... Here is how you would do it with a multi-purpose VisibilityConverter: public class VisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo...
3 May 2023 by Member 12692000
Hi, I'm trying to follow MVVM pattern and want to hide a certain grid in my WPF app where there are two conditions e.g. right now I've something like What I have tried: ...
3 May 2023 by Richard Deeming
For something this simple, you just need to add two triggers:
1 May 2023 by Graeme_Grant
If you want someone to write code for you, then there are these services: * fiverr[^] * Upwork[^] * Freelancer[^] * Guru[^] * PeoplePerHour[^] * TaskRabbit[^] * Karat[^] Or, if you're trying to work it out yourself, then there are many tutorial...
1 May 2023 by Member 15981966
Create a WPF Application that requests for feed from Flickr(Search API) and then bind to WPF Control. What I have tried: I'm able to get the data in an XML Document in ViewModel but unable to bind it to the ListBox in View
30 Apr 2023 by Richard MacCutchan
If you are expecting someone here to do the work, then I am afraid you will have a long wait. This site is not here to do your work. We only provide assistance with problems in the code that you write.
5 Mar 2023 by Jo_vb.net
Use docking framework, MVVM Toolkit and some features
18 Feb 2023 by Christopher Fernandes
How to pass & read command parameter in ViewModel
18 Feb 2023 by Graeme_Grant
Use the MVVM ToolKit[^]. One of the thinks that they have is a RelayCommand[^] that will make life simple for you. But if you want to roll-your-own, here is one that I use: public class RelayCommand : RelayCommand { public...
17 Feb 2023 by Serhii Krotkykh
Example of using result builder for the MVVM pattern
10 Feb 2023 by Graeme_Grant
Binding to a Tag is not how I would do it. But, as this is how you want to, will need to write an IValueConverter[^] to work with the Tag property: public class CharConverter : IValueConverter { public object Convert(object value, Type...
10 Feb 2023 by Christopher Fernandes
I have a WPF ComboBox as listed below ...
3 Feb 2023 by Graeme_Grant
You need to use a CollectionViewSource[^] to filter your sub-collection. Microsoft have hte following example: How to: Filter Data in a View - WPF .NET Framework | Microsoft Learn[^] Here is a working example put together to demonstrate how to...
3 Feb 2023 by Member 12692000
I know there are quite a few posts on the internet regarding how to implement cascading combo box following mvvm in a WPF c# app but I still could not make it work in my case. Can anyone help me with this ? I have a model with some properties...
31 Jan 2023 by Christopher Fernandes
I have a WPF Login window with a username, password textbox & 7 textboxes for OTP since OTP is 7 digits long. How to bind the ViewModel property "LoginOTP" to these 7 OTP textboxes on the Login View. Should I create 7 different OTP properties...
31 Jan 2023 by Graeme_Grant
I would make a UserControl that would bind to a property on the ViewModel and internally split the string into the 7 parts, each bound to the 7 TextBoxes. To the ViewModel, it would appear to be a single binding, like a single TextBox. The...
16 Jan 2023 by DaDutchpaddy
I found this a good place to start: https://stackoverflow.com/questions/1405739/mvvm-tutorial-from-start-to-finish[^]
16 Jan 2023 by Christopher Fernandes
Can anyone guide me to a paid or free tutorial as to how to use mvvm in wpf with localdb. I am tasked with converting a Winforms app to WPF MVVM. I dont know where to begin. What I have tried: i tried caliburn micro but i need complete control...
16 Jan 2023 by Mike Hankey
We have a in-house WPF guru that has a series of articles on WPF MVVM. Start here; Bare Metal MVVM - Where the Code Meets the Road - Part 1[^]
16 Jan 2023 by Graeme_Grant
This is the best tutorial that I have found for WPF MVVM: Models - WPF MVVM TUTORIAL #1 - YouTube[^].
29 Dec 2022 by Graeme_Grant
To access properties via data binding that are not normally reachable, like the Columns.Count property of the DataGrid control, you can write a wrapper around the control and add a custom property. public class MyDataGrid : DataGrid, IDisposable...
29 Dec 2022 by Member 12692000
How can I dynamically get the column count of a WPF datagrid inside a viewmodel method following mvvm ? What I have tried: Essentially datagrid.columns.count to a int variable but using mvvm.
8 Dec 2022 by Ramana Bellary
I have created a WPF project with MVVM pattern. I have a Customer Entity class. I have a NewCustomer userControl whose datacontext is CustomerViewModel which has a property Customer of type Customer Entity. The usercontrol has fields like Name, Id, Country.. My requirement is the combination...
8 Dec 2022 by jaysuvius
Use Interactivity Behaviors xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
8 Dec 2022 by Ramana Bellary
I want to implement TextBox LostFocus event in my WPF window which should be fired in my ViewModel so that I can validate the value. Even parameter should be passed to the command. If we can use Attached Command Behavior, so anyone can please share an example.Note: I am using MVVM...
8 Dec 2022 by jaysuvius
I was able to solve using interactivity behaviors. XAML xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:vm="clr-namespace:myNameSpace.ViewModels" ...
25 Oct 2022 by User 14130253
for example in database i have country and city of that country and I want create a expander or anything like expander that can help me for group content that is like expander (hide and show data) that have country name and in expander I want add...
25 Oct 2022 by Graeme_Grant
I think that this is what you are looking for: ListView grouping - The complete WPF tutorial[^]. The tutorial shows you how to use groups with a ListView control and how to make the group expand and collapse.
11 Oct 2022 by olegul86
Hello. I am trying to simply populate a ComboBox with data from a Sql server table column (adhering to the MVVM design pattern), and do not understand why it is not working. I am binding it to a BindableCollection (Stylet framework), which is...
21 Sep 2022 by Member 13379347
I have a ContentView with a Bindable property. This property is set from the main page and it is setting correctly as I am seeing it in PropertyChanged function. Now I want to bind this value to the property of ViewModel of ContentView. I can...
21 Sep 2022 by Graeme_Grant
you set the binding to: But above you state the class/file name is ViewModel.cs In the ContentView.xaml, use:
6 Sep 2022 by Robert S4r
After frequent search on almost all sites, I've failed to get a solution to the problem. My datagrid is bound to SQL server database using entity framework hence no MVVM pattern. The copy from datagrid seems to work with a few codes (seems...
9 Aug 2022 by Member 10321925
I have two UserControls in my MainWindow and UserControl2 has 2 Listboxes,Texboxes and Buttons.When i write some text in TextBox and press Button it should add into the ListBox.Can somebody help me with the code,i'm new to WPF and MVVMThis is my XAML code
3 Aug 2022 by Code4Ever
I have used the following code to turn the UI event into a command:
2 Aug 2022 by EstKells
I have this Property: private string _TextBox1 = "Input"; public string TextBox1 { get { return _TextBox1; } set { _TextBox1 = value; ...
2 Aug 2022 by Gerry Schmitz
https://stackoverflow.com/questions/49767595/how-to-navigate-to-previous-page-in-wpf-but-keep-the-data[^]
30 Jul 2022 by Richard MacCutchan
MvvmCross | MvvmCross is a convention based MVVM framework for Xamarin and Windows, with strong community support, filled to the brim with useful features.[^]
25 Jul 2022 by Federico Alterio
Get rid of all that MVVM boilerplate code just to bind an expression to other properties
20 Jul 2022 by Code4Ever
I use the following codes to navigate between views: public class MainPageViewModel : ViewModelBase { #region Properties private object _selectedViewModel; public object SelectedViewModel { get {...
20 Jul 2022 by Graeme_Grant
It's suggesting that you have the VM being created twice. To debug and identify the cause: 1. Place a breakpoint in the constructor of the view model 2. Run the app. 3. When the breakpoint is hit the first time, look at the call stack in the...
19 Jul 2022 by Ken Schneider
I have a grid inside a stack panel. On the grid I will place several different textboxes that will show positional values that the boxes are databound from my database. I will want to have buttons to increment/decrement by small, medium, large,...
19 Jul 2022 by Graeme_Grant
It looks like you are at the beginning of learning WPF & MVVM. I strongly suggest that you do some googling for: wpf tutorials - Google Search[^] & wpf mvvm tutorials - Google Search[^] - there are a number of great free websites and youtubers...
18 Jul 2022 by Member 14047666
I have a WPF desktop app built with MVVM and have all the views available in MainWindow.xaml. In left side of MainWindow.xaml displaying Media stuff and Right side of the MainWindow.xaml displaying other usercontrol. In MainWindow.xaml.cs...
18 Jul 2022 by Graeme_Grant
I am guessing that you are using ObservableCollection to hold your data for the grids in the ViewModel. You have two issues here: 1. Loading the data into the ObservableCollection is happening on the UI thread, effectively blocking the UI from...
18 Jul 2022 by Phil J Pearson
Each view should have its own view model and the viewmodel should be the datacontext for the view. Then you can have as many views as you want, just update each viewmodel (or its model) as necessary. That's what MVVM means. ViewModel properties...
3 Jul 2022 by Member 12692000
I'm trying to show the column values of the selected row of a wpf datagrid to different textboxes without breaking the mvvm pattern. I'm relatively new to the mvvm. Here is my XAML:
7 Jun 2022 by hardover
I am using WPF MVVM for a project. I have 8 View/ViewModel pairs that work well for the solution, but I have found myself duplicating two event handlers in code-behind for each View: OnLoaded and ExpandDetail (which is needed to respond to a...
14 May 2022 by Code4Ever
I'm using MVVM architecture in my test project. I have a ListView. The data is bonded to the SQLite database. I want to delete all selected items from the database. The delete button should be activated if at least an item is selected. I cannot...
14 May 2022 by Code4Ever
The following StackOverFlow link solved my problem: c# - Binding SelectedItems of ListView to ViewModel - Stack Overflow[^]
11 May 2022 by saman.h
Hi,when i add new row to data grid programmatically also add a new place holder in bottom of my WPF data grid.I set CanUserAddRows=True in xaml code.How i can hide or remove new place holder row of WPF data grid?Thanks.Sorry for bad English.
8 May 2022 by Graeme_Grant
In Part 1[^] of your questions, we addressed how to: 1. Pass text to a ViewModel when a Button is pressed 2. Dynamically add new TabItems with specfic TabItem Header names when the Button is passed. Now you require: A. How do I display content...
8 May 2022 by Code4Ever
I have three buttons. I want to dynamically add a new tab by pressing each button. Each button has its specific content. What I have tried: I tried the code proposed by the user Graeme_Grant in How to pass a string from view to the viewmodel in...
8 May 2022 by Graeme_Grant
The trick with MVVM is the View is a visual representation of the data. The ViewModel is the interface between the data and the view. So for the Tabs to reflect the Button clicks, you should be binding the Tabs to the data and the Button clicks...
8 May 2022 by Code4Ever
I have three buttons with different names. I want to pass the text of the pressed button into the ViewModel and fill the value of the TabName property. How can I do that? In the following code, the TextBlock works as a button. What I have tried:...
8 May 2022 by Jo_vb.net
I think the best is using EventTrigger Requirements: Microsoft.Xaml.Behaviors.Wpf (NuGet package): like it is shown in my article (in Vb.Net but same should be possible with C#): VB.NET MVVM Toolkit Demo[^] Example: ...
25 Apr 2022 by Code4Ever
I want to show a live clock in my WPF project. I'm using the MVVM pattern. The problem is that the clock is not shown. I debugged _currentTime and it was getting a time value every second. How can I fix it? What I have tried: The ViewModel is:...
25 Apr 2022 by Chris Copeland
The problem is here: _currentTime = string.Format("{0}:{1}:{2}", d.Hour.ToString("00"), d.Minute.ToString("00"), d.Second.ToString("00")); You're setting the backing value of the property directly, rather than setting the property itself. You...
14 Mar 2022 by Paulo Zemek
Mistakes that can be made while using MVVM and how to overcome them
21 Feb 2022 by Member 7912784
I want to add a navigation bar in side my views to move to sub view However when i change the side menu bar selected item nothing show here is the project sours code https://github.com/markoshenoda/NeedHelp.git What I have tried: I tried...
21 Feb 2022 by Graeme_Grant
It looks like you have a binding issue. INotifyPropertyChanged does not look like it is correctly implemented. Your code: public event PropertyChangedEventHandler PropertyChanged = (sendr, e) => { }; Corrent implementation: public event...
20 Feb 2022 by Graeme_Grant
I had a quick look at your github code and it is incomplete. ViewModels are missing. So I could not run your code to see what you are trying to do. Looking at the code above, you're trying to navigate by ViewModel. Here is your code for the...
18 Feb 2022 by antobaro
Hi All, Scenario : a process write a textfile and in meantime another with the progress bar show current situation. At the end a messagebox show Done What's wrong ? The code doesn't show the progress situation, and only at the end I can see...
13 Feb 2022 by antobaro
Hi, I can't update a text box via a timer. This is the declaration of the texbox and the property private string _RowsImport; public string RowsImport { get { return _RowsImport;...
13 Feb 2022 by Jo_vb.net
Read your post from yestarday: Why a variable in binding doesn't refresh in a timer?[^]
12 Feb 2022 by antobaro
Dear All, my issue is: why a binding variable doesn't refresh in a tread ? this is my Scenario: in my view I have defined this textbox and this is the property private string...
12 Feb 2022 by M Imran Ansari
Check the following link, hope it will help you: c# - WPF Binding not updating from DispatcherTimer - Stack Overflow[^]
12 Feb 2022 by #realJSOP
This might help: Update a WPF UI from Another Thread – Stephen Haunts { Freelance Trainer and Writer }[^]
3 Feb 2022 by Roy Mustang 2022
I am trying to change button's color when it is clicked. But it is not changing color. Here is my code. What I have tried: private SolidColorBrush[] _btnBrush; public SolidColorBrush[] btnBrush { get { ...
2 Feb 2022 by Richard Deeming
You are changing an element within an array. That will not raise any "property changed" events, so the UI has no idea that the binding needs to be updated. Try replacing your array with an ObservableCollection: public...
27 Jan 2022 by Jo_vb.net
My idea was to host a WPF user control with Ribbon within a WinForm VB.NET project and try to use MVVM pattern.
11 Jan 2022 by Jo_vb.net
My idea was to host a WPF user control with Ribbon within a WinForm VB.NET project and try to use MVVM pattern.
26 Dec 2021 by OriginalGriff
Repost: Deleted. Please do not repost your question; add information or reformat it by all means, but posting it repeatedly just duplicates work, wastes time, and annoys people. I'll delete this one.
17 Dec 2021 by adriancs
At the app.config, add the following: Read more about "gcAllowVeryLargeObjects - Microsoft .NET Documentation" and em... yupe, as Dave...
17 Dec 2021 by sreeCoderMan
HI I get this exception when i run the tool for more than 3 hours i do have 16GB RAM , 64Bit OS Intel Core i7 4770 CPU and 150 GB HD Application: PRO.LoadTest.exe Framework Version: v4.0.30319 Description: The process was terminated due...
9 Nov 2021 by DoingWork
Hi Friends I have 2 different user controls i.e. ViewAUserControl.xaml , and ViewBUserControl.xaml . These controls are added dynamically in dynamic tabItems where each tabItem contains any single userControl from availabe 2 UserControls, whom...
9 Nov 2021 by pszyjaciel
In the ViewAUserControl.xaml: xmlns:local="clr-namespace:WpfPractice.ViewModel" In the ViewBUserControl.xaml: ...
4 Nov 2021 by #realJSOP
A tool to generate model and viewmodel classes directly from your selected database
4 Oct 2021 by Kamran Sultanlı
I haven't specified what happens when you hit the copy button or when you hit the clone button, and frankly I don't quite know how to do it. I need to create a wpf application with 2 buttons in a homework. one of the buttons is "copy" and the...
4 Oct 2021 by George Swan
I am not sure what you are trying to achieve but it seems to me like you have an exercise in data binding. Here is an example that may be helpful.
4 Oct 2021 by Member 12938297
hello sir, i have 5 textbox .... 4 for entering input value and 5th one for storing result. i used textchange event and those event i implemented in view(.cs file).. but i want to implement same in view_model file... how to to do the same using wpf and mvvm technique.. What I have tried: ...
4 Oct 2021 by Chris Copeland
There's two things you need to be aware of really. First is using binding to bind the content of the textboxes to a string within the CopyCloneViewModel. You would need to add a property to the view-model and then use binding in the XAML so that...
27 Aug 2021 by Mohammad Nawaz
Hi I have created a MAUI project in VS 2022 preview, which is working fine initially with emulator, but now Emulator is not showing. When I create Xamarin project Emulator is showing and application is running on that Emulator. Please help me...
27 Aug 2021 by Dave Kreskowiak
You should NOT be using a preview product to develop a production application. If you're running into problems with using VS2022, you need to report this problem to Microsoft so they can fix it. THERE IS NO FIX FOR YOUR PROBLEM UNLESS YOU...
26 Aug 2021 by Richard Deeming
You're using a preview product, so there are bound to still be bugs in it. After all, there are still plenty bugs in the non-preview versions! You should report the problem to Microsoft so that they can investigate: Visual Studio Feedback[^] ...