C# - MVVM ViewModel Default Constructor?

May 25, 2011

I have been getting up to speed with the MVVM pattern in Silverlight and was wondering how to implement binding from the View to the ViewModel when the ViewModel constructor has a parameter if an interface type.If I bind the viewmodel to the view in XAML then you can not use a parameterised constructor. Given that I was creating a default constructor passing an instance to the parameterised constructor but this breaks the abstraction.

View
<navigation:Page x:Class="QSmart.DataViewer.Report.RecentFailures.Report"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

[code]....

Is it recommended to use the code behind of the view to pass into the parameterised constructor and then bind to the viewmodel?

View 1 Replies


ADVERTISEMENT

WP7 MVVM - Call Me.setfocus() From The ViewModel?

Apr 15, 2012

I'm attempting to improve my MVVM abilities in my next WP7 App (which is written in Vb.NET). I have a textbox that has been given focus and has a WP7 keyboard displayed. I am using command binding and a xyzzer's bindable Application bar (which is excellent).[URL] I want to be able to cancel the focus of the TextBox from the ViewModel, by setting focus on the form. Normally (Non MVVM) I would do this from within the form by calling:

[Code]...

View 3 Replies

.net - WPF MVVM Implementing The Viewmodel To Reflect The Base Model?

Jul 4, 2011

Something that has been confusing me for a while now with WPF MVVM is for example, when I have a base model containing nothing but a few properties and some validation code and I then build a view model around this base model, how should the view model be structured.

For Example:

Base Model ->
Imports ModellingHelper
Imports FTNHelper

[Code]....

What I am wondering is, if there is a better way to structure the view model to improve data binding, so I don't have to bind to Source.Name etc. How should I handle the base model in the view model?

View 2 Replies

Implement A Constructor In MVVM Unity?

Feb 28, 2012

I have just started using MVVM design pattern with unity and I'm strugling to work out how you add a constructor.my code currently works if I comment out my constructor that requires input the view gets added to the shell.

Protected Overrides Sub ConfigureModuleCatalog()
MyBase.ConfigureModuleCatalog()
Dim moduleCatalog As ModuleCatalog = CType(Me.ModuleCatalog, ModuleCatalog)
moduleCatalog.AddModule(GetType(GridModule))
End Sub

how do I pass in variables into my GridModule ?

View 5 Replies

Default Value At Declaration Or In Constructor?

Mar 4, 2011

One would think I'd already know this, but I never really gave it much thought before now. When declaring a member variable for a class, is it better to set the default value at the declaration

Private m_strMyVariable As String = ""
Or is it better to do it in the constructor
Private m_strMyVariable As String

[Code]....

Should I maybe always specify a value at declaration, even if it's Nothing, and just override that value in the constructor(s) as needed? Or is it situation specific? If so, a really quick rundown of which situations might warrant which treatment would be nice.

View 4 Replies

VS 2010 How To Eliminate Default Constructor

Jan 19, 2011

I have written a number of classes in my time in VB.NET which set the basic elements in a custom New constructor through parameters. This makes things easier and enforces discipline. However, using Public Sub New() becomes pointless. If someone else tried to use this class, he or she could make a mess of it all by using Sub New without the arguments. I'd like to remove this method but I haven't found out how. I could make it raise an exception, but that somehow seems unseemly. I'd like a neater way. Does anyone know how?

View 22 Replies

VS 2008 - Creating Default Constructor Within Class

Feb 3, 2010

I'm doing a lab for school, and I came across something I have never done before: create a default constructor within my class. It involves creating a private field to store the connection string, then create a default constructor that sets the connection string.

Here is what I have so far:
Public Class Appointments
Private sqlconnection As String = ConfigurationSettings.AppSettings("ConnectionString")
Private Property connectionstring() As String
Get
Return sqlconnection
[Code] .....

View 3 Replies

VS 2010 Dll That Is Implemented By A Class With A Default Constructor

Dec 27, 2010

I have a base class which must be overriden. This base class sits in one dll shared by all. The derived classes will each be in their own dll such that the addition of a new derived class can be done by distributing a new dll. The set of dlls, and therefore the set of derived classes, will be discovered by the main program on startup. That's all pretty straightforward. The problem is that the main program needs to be able to query a database to figure out which type of derived class it needs, then create a class of that type. Naturally, it can't know which types will be available ahead of time because even I don't know that. The program has to be dynamically extensible.The obvious way to do this is to have an interface in the dll that is implemented by a class with a default constructor. The sole purpose of that class would be to return an object of the type (one of the derived types) defined in that dll. The derived types can't really be this class, because they can't have a default constructor since the base class doesn't have a default constructor, and the derived class can't make up the arguments that the base class constructor needs.

So basically, each dll that houses a derived class would also house a simple class that implemented an interface for the sole purpose of creating that particular derived class. The main program would examine the dll to find a class that implemented the interface, and once it found one, it could ask it what type of class it created, or it could ask it to create an instance of that class. It seems like there ought to be an easier way to dynamically add new classes to the project. It seems like the derived class ought to be able to tell the main project what type it was. This could be done, except that the derived class would have to exist before any of its methods could be called unless the methods were shared. Since you can't have a shared method in an interface, the interface itself would make no sense at that point, in which case I would need to discover whether the class in the dll derived from the base class in the second dll, just to figure out whether or not I wanted to create it. That's getting convoluted by now, so I guess I'll leave it there. The basic point is that the base class is known to the main program from a common dll. The number and types of derived classes can't be known at this time, so the program has to be able to discover them dynamically. Each derived class will sit in its own dll (or there could be more than one in a dll), and has to be discovered, and instances created, as needed, by the main program.

View 2 Replies

Winforms : Where Is Default Constructor Of A Windows Form

Jan 1, 2011

where can I find the default constructor of a windows form? I mean:

Public Sub New()

End Sub

I should say that I Use Visual Studio 2008 as my editor.

View 3 Replies

Wpf - PageFunction OnReturn And The Default PageFunction Constructor?

Mar 16, 2012

I'm trying to create a Wizard at runtime in VB.NET using the WPF NavigationService and I'm having some problems. I need to add controls to the PageFunction pages at runtime which seems to involve passing arguments to the PageFunction pages when I create them (prior to navigating to them). This means that the PageFunction pages need to override the default constructor and add arguments to it. This seems to work fine.

The problem is that I also need to call OnReturn once I've navigated beyond the first page (to go back to a previous page) but the OnReturn doesn't work unless I use the default constructor on the PageFunction page it is navigating back to. The work around I've been considering is creating some global values that the PageFunctions could acssess at runtime in their default constructor but I can't figure out how to define global variables in the MainWindow that the PageFunction pages can get access to.

View 1 Replies

Pass A Delegate Into A Constructor Of An Abstract Class From A Descendant's Constructor?

Feb 15, 2010

I have an abstract class which requires a delegate to function. I pass the delegate into the constructor. Now that I have a non default constructor I need to call the abstract class's constructors from the concrete class which means that I need to use MyBase.New(...). I have included a quick example below.

Public MustInherit Class BaseClass
Public Delegate Sub WorkMethod()
Private _Work As WorkMethod

[code]....

I have tried to do this but I keep getting the following error: "Implicit reference to object under construction is not valid when calling another constructor".Can I not do what I am trying to do above? I initially had the delegate setup in its own setter method. But then I am creating a deceptive API because it does require a point to a method to work properly.

View 3 Replies

Why Is Constructor Call Valid Only As The First Statement In An Instance Constructor

Nov 2, 2009

what's the rationale behind this limitation: Constructor call is valid only as the first statement in an instance constructor i want to pass an argument to my constructor which validates this argument and calls mybase.new according to this argument but it doesn't let me

example:

Public Class prob
Inherits System.ApplicationException
Public Sub New(ByVal problem As String, ByRef inner_exception As Exception)

[code]....

View 16 Replies

Asp.net Mvc - ViewModel Object Is Not Preserved

Jul 14, 2010

I am sort of new to MVC so pardon my ignorance. I am using IoC ( StructureMap ) and I have a need to pass in an instance of what I consider to be a set of Controls to each view, so I have created ViewModels in order to accomodate this. The view model is populated with an instance of the Controls and the View is then rendered. When a user performs a POST, the Controls are not being passed back to the Action.

[Code]...

View 1 Replies

.net - ASP.NET MVC Bulk Data Update With ViewModel?

Aug 14, 2011

Im trying to bulk update. I want to use viewmodel pattern. I read this article and create program. Program show Database value and html looks ok. But After submit, Controller couldn't get values. Every values are 'Nothing' please point me where I missunderstanding.

Public Class users
Public id As String
Public username As String

View 1 Replies

Call A View's Method From Within Its ViewModel?

Apr 30, 2012

I am new to Silverlight, but am up to my ears in some of the more intermediate/advanced stuff.

I am using MVVM, in Silverlight 5.

I have a view (we'll call it ComboView.xaml). It has a ViewModel (we'll call it AwesomeVM)

The view contains the ViewModel, declared in the page's resources like so[code]...

View 1 Replies

Creating Viewmodel With More Properties By Deriving A Class?

Nov 26, 2010

I was hoping to make a PersonViewModel class from an EF Person class, so I can expose more bindable properties.

Public Class PersonViewModel
Inherits Person
Public Sub New(ByVal P as Person)

[code].....

View 9 Replies

Looking For Tutorial On MVVM Using WCF And WPF?

Mar 14, 2011

I'm wondering if someone can point me towards a good article/tutorial explaining how to use the MVVM pattern in an WPF Application that uses WCF web services. My WPF client calls a service reference to get data objects that contain data from the database but from everything I've seen and read so far about MVVM I am still not clear on how to use MVVM to work with the data objects I am retrieving from the WCF services.

View 1 Replies

WPF & MVVM: Any Examples Using VB?

Sep 26, 2009

Almost every example of MVVM I found is coded in C#, are there any examples/tutorials coded in VB.Net? I'm having a hard time translating C# to VB.Net since I haven't really used C# in any meaningful way...Also, does a MVVM Template/Toolkit for VB.Net exist yet?

View 4 Replies

.net - MVVM Design Consideration

Feb 3, 2011

I am currently developing a new WPF application and have the majority of my business logic layer developed (ie my Models). I am about implement ViewModel classes to represent one feature of my application. I am quite new to the Model-View-ViewModel pattern and I have a question about which approach would be best to use when implementing my ViewModel classes.

[Code]...

View 3 Replies

C# - Reusing A Menu With Mvvm And Wpf?

Jun 7, 2011

I was wondering what the best approach is for sharing a menu across all wpf windows/views. My Application doesnt really fit the navigation model, so will probably use a Ribbon control. I am leaning towards creating a user control for the menu and dropping it on each view, but have also seen Josh Smith's msdn article, where he loads user controls.

View 2 Replies

Implementing MVVM In Silverlight?

Nov 11, 2009

IM Looking at Implementing MVVM in Silverlight.Kind of new to Silverlight and I'm Definately new to MVVM Pattern.I get it all But I want A set of small Prism VB.Net MVVM exmaples if that makes sense.

View 1 Replies

Way To Requery CanExecute In Silverlight MVVM?

Mar 22, 2011

I have a simple LoginForm.Here is how the code-behind looks like:

Private Sub btnLogin_Click(sender As Object, e As RoutedEventArgs) _
Handles btnLogin.Click
If Me.loginForm.ValidateItem() Then

[code].....

View 1 Replies

Wpf - Bind A DataGridComboBoxColumn To EntityFramework Using MVVM?

Feb 16, 2012

I'm trying to get a DataGridComboBoxColumn working with my ViewModel. Everything appears to work correctly but when I change the value of the combo box, the entity isn't changed. The datacontext of the window has these properties:

[Code]...

View 4 Replies

.net - Pieces Required For A Usable MVVM Framework?

Sep 17, 2010

As my company migrates towards the .NET framework from VB6, it looks like we are going in the direction of WPF (my boss is in love with the Office-style Ribbon control). I've been working to mock one of our VB6 applications in WPF and decided to experiment with MVVM at the same time. I'm being discouraged from using an existing MVVM framework, so I guess I need to write my own. The biggest concern right now seems to be a method for registering and managing all my views from a central spot - a manager class - but I'm not exactly sure how to implement this.

View 4 Replies

Implement Extensive Data-Validation In MVVM?

Jul 14, 2011

Possible Duplicate:How can I handle a Validation.Error in my ViewModel instead of my View's code behind?The usual examples of how to use Data-Validation in WPF usually only involves defining an error template for the control and displaying the error message in the control tooltip. What I want to do is to create a collection of all ValidationErrors, display it in an ItemsControl to the user and focus the invalid control when the user clicks on the associated (error) item in the ItemsControl.

View 2 Replies

Wpf - Bind To SelectedItems From DataGrid Or ListBox In MVVM

Mar 26, 2012

SEE MY ANSWER AT THE BOTTOM Just doing some light reading on WPF where I need to bind the selectedItems from a DataGrid but I am unable to come up with anything tangible. I just need the selected objects.

[Code]...

View 3 Replies

.net - Call Winforms-style Invoke/Delegate From MVVM?

Oct 12, 2010

I'm hacking away at some code which seems to have been started, at least in theory, as an MVVM project in Expression Blend, by my predecessor at this company.

I've got a thread running in the background, which is running some operations on items as they happen. In order to prevent any clashes, I've also got that thread running any operations my users call for.

Once those operations are completed, I'd like to bring up a MessageBox to give a summary of the user-initiated operations, but now that they're running off in their own thread, the finishedProcessing event handler is now running on the background thread instead of the interface thread and it's causing my MessageBoxes to appear non-modally.

Back in the WinForms days, I'd have handled that using InvokeRequired, Invoke and a Delegate. I've read that this has been replaced by something called "Dispatcher", but the ViewModel class I'm using doesn't seem to have a Dispatcher object.

The "thisViewModel" class I'm using inherits a class called "WorkspaceViewModel", which inherits "ViewModelBase", both of which look generated to me...

where I can link up to this "Dispatcher" from here?

View 1 Replies

.net - Loading And Saving Data In WPF Using The MVVM Pattern And DataGrids

Jan 4, 2011

How do i fill my ObservableCollection(of Monitors) with data so that I can save it in an MVVM friendly manner. I normally use a FileNumber to load a DataSet using a DataAdapter and pass the monitors table via monitorDT - should I be loading it differently? How do I save the changes? Right now I have the following for loading data:

[Code]...

View 1 Replies

.net - Loading And Saving Data In WPF Using The MVVM Pattern And DataGrids?

Jan 13, 2011

How do i fill my ObservableCollection(of Monitors) with data so that I can save it in an MVVM friendly manner. I normally use a FileNumber to load a DataSet using a DataAdapter and pass the monitors table via monitorDT - should I be loading it differently? How do I save the changes?Right now I have the following for loading data:

Public Class Monitors
Inherits ObservableCollection(Of Monitor)
Public Shared Function LoadMonitors(ByVal monitorDT As DataTable) As Monitors

[code]....

View 3 Replies

C# - Tab Data Lost On Selected Item Changed MVVM?

Mar 23, 2012

I have been trying to do this for ages and having no joy whatsoever.

I have a ribbon window of the following hierarchy:

MainWindow
MainContent (Tab Control)
TabContainerViewModel
ViewModelBase

View model base has an ObservableCollection of tabs type ViewModelBase. The Tab Control itself is binding fine to these, displaying appropriate view models. I have 2 problems however, I want a "NotepadView" (Of type viewmodelbase) to be replicated numerous times (one view many view models).

At the minute, I have 4 views (NotePadViewModelx where x is 1-4) with corresponding viewmodels, this is because each view had the same text per tab. Now I have individual views per tab.

When I type into tab 1 and switch to tab 2, I lose what I typed in tab one when I click back.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved