.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

MVVM. Access TabControl->TabItems from ViewModel

Posted By:      Posted Date: August 30, 2010    Points: 0   Category :WPF
Hi Folks,   Well, I just start to use MVVM, and I want to migrate functionality from my old non mvvm project to my new mvvm project.   The problem is the following one: In my old app (wizard application), I use tab control. And I have such things as States there. For this purpose I use StateMachine approach: My tab control looks like:   private void sm_StateChanged(State current, State previous, State next) { switch (current.Name) { case StatesNames.WELCOME_SCREEN_STATE_NAME: MainTabControl.SelectedIndex = 0; break; case StatesNames.SERVER_SUMMARY_SCREEN_STATE_NAME: MainTabControl.SelectedIndex = 1; preCertificationTabControl.SelectedIndex = 0; break; case StatesNames.SERVER_DEFINITION_SCREEN_STATE_NAME: MainTabControl.SelectedIndex = 1; preCertificationTabControl.SelectedIndex = 1; break; case StatesNames.UPGRADE_PRECERTIFICATION_SCREEN_STATE_NAME: MainTabControl.SelectedIndex = 1; preCertificationTabControl.SelectedIndex = 2; break; case StatesNames.PRECERTIFICATION_SCREEN_STATE_NAME: NavigationStateMachine.GetInstance().SwitchToNextState(); break; } } Well, as you can see, I need to access my tabControl to indicate states :( but it is not correct from

View Complete Post

More Related Resource Links

(MVVM): Call Method On ViewModel From View

Hey All,   In my View, I would like to call a method on my ViewModel (all from XAML). View: <!--Parameters--> <ListView Grid.Row="2" DataContext="{Binding}" ItemsSource="{Binding}"> <ListView.View> <GridView AllowsColumnReorder="True"> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Key}"/> <GridViewColumn Header="Value"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Value, Mode=OneWay}" MinWidth="100" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> ViewModel (the Method I want to call): public ReadOnlyScriptParameterCollection GetParameters(string scriptFullTypeName) { ReadOnlyScriptParameterCollection sps = null; var scriptHost = ScriptHost.Create<JdsScriptHost>(); scriptHost.LoadFromAssembly(ScriptAssemblyPath, scriptFullTypeName); sps = scriptHost.ScriptParameters; return sps; } Is there

How To Setup Expander Control for TabItems in TabControl?

Hii.. I'm having a TabControl which TabStripPlacement is left side means all TabItems are exist in left side of window (Look like side menu).. so i want to place Expander control for TabItems only, which is used like expand the expander and select respective TabItem and close expander like that.   sample picture...                        _________________________________________________________________________ TabItem1   E   |                                                                                                                               | TabItem2   X   |      &n

MVVM: How to bind a page in a tab control with a viewmodel?

We practise MVVM pattern.
We have a main window which contains tab controls. Each tabItem contains a page.
Since the main window needs to share some data with one of page, so our MainWindowViewModel creates the instance a RunconditionViewModel.
Then we need to set the instance of RunconditionViewModel to one of page's DataContent (page called ControlPage.xaml).
How do we achieve that? see the code below.

In HDMainWindow.xaml,
<TabControl x:Name="tabControlMain" DockPanel.Dock="Left" MinHeight="200"  SelectedIndex="0" TabStripPlacement="Left" >
<TabItem Header="Run" Name="TabItemControlPage"> <Frame Name="FrameControlPage" Source="Features\Basic Control\ControlPage.xaml"></Frame> <!--<Frame Source="Features\Basic Control\LoginPage.xaml"></Frame>--> </TabItem> in App.xaml.cs,

protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); InitializeComponent(); HDMainWindow hd = new HDMainWindow(); HDMainWindowViewModel hwd = new HDMainWindowViewModel(); hd.DataContext = hwd; //if (hd.TabItemControlPage != null) // hd.TabItemControlPage.DataContext = hwd.RunConditionsViewModel; if (hd.FrameControl

MVVM how to move event handler from code behind to ViewModel


First of all I'm fairly new to WPF and MVVM. For learning purposes I created a very simple MVVM test app similar to the one demonstrated here: http://windowsclient.net/learn/video.aspx?v=314683

I am trying to find out how to work with events in the MVVM pattern. To work with events in the xaml code behind is simple. But how to move the code to the ViewModel?

In the xaml I have:

    <StackPanel Background="{Binding BackgroundBrush}">
        <ItemsControl ItemsSource="{Binding AllEmployees}">
                    <StackPanel Orientation="Horizontal">
                        <TextBox Width="100" Text="{Binding FirstName}" />
                        <TextBox Width="100&q

Hit Testing in MVVM, from ViewModel


Hello all.

How can I go about performing a HitTest on a View, from the associated ViewModel?

I have a ViewModel that is controlling a secondary pointer, which can move around the associated View.  Under certain conditions I want my ViewModel to trigger that a "click" has been performed, and would like to send that "click" through to my View; or would like to detect what is there so I can perform certain actions in the ViewModel and trigger Bindings so the visual objects alter their look to correspond to that "click".

Thanks for any help!

MVVM Bind View Details to Model Via ViewModel when a Button clicked.


I have model called Car with prperties name,model,type,year.

I have implemeted the Viewmodel with same properties with OnpropertyChangedEvent including model object type Property.

I have a view usercontrol where textboxes for name, model and for year a combobox.

Whenever i fill the view i want to save those details into model via view model

I have written ICommand  Save which calls SaveCarDetails defined in viewmodel,  which is bind to a button in view ,All other texboxes text is bind to the properties of viewmodel properties.

When i put break point at ICommand SaveCommand and SaveCarDetails Function i could see the values filled from view.

But when i bind these details to another user control where listbox is placed and its itemsource property is set to Car property nothing but model object defined in the viewmodel.

I couldn't see the values binding via viewmodel to model.

Where as if i bind to textboxes in the listview i could see the values because i it's a dependency property.

Can any one please tell me what is the wrong i am doing here.




Dialogs and ViewModel - Using Tasks as a Pattern

The ViewModel/MVVM pattern continues to gain popularity, with a blog post showing up every so often, and with tweets and retweets popping up even more often :-). At the same time, there are some interesting topics beyond the core pattern that continue to fuel experimentation. A big one amongst those is how should applications use dialogs when using the view model pattern.

The crux of the problem is the desire to keep the view model independent of UI concerns, and ensure it can be tested in a standalone manner, but that often comes to odds when you want the view model to launch a dialog, and/or do some work after the dialog is closed.

WPF: If Heineken did MVVM Frameworks Part 4

MVVM is to have an instance of a particular Model (say currentPerson) inside my ViewModel (say PeopleViewModel) which is exposed to the View (say PeopleView). The View binds and edits the Model directly.

This definitely flies in the face of what most people consider to be the holy grail of MVVM pattern, but it's a fairly new pattern, so people are still finding their way with it every day, and this works for me very well. The reason I do what I do, is for the following reasons:

1.I have always had the luxury of being able to write my own UI specific Model classes. I would even do this if I was using some other Model classes first, such as LINQ to SQL or LINQ to Entity Framework. As these classes don't have everything a proper WPF Model class needs in my humble opinion. Though, they are pretty good, as they are Partial classes and use INotifyPropertyChanged/DataContract etc etc
2.I am a pragmatist and I do not like writing code for the sake of writing code. I have seen some MVVM apps where the author has had a Model with 50 properties on it, that are simply repeated in the ViewModel abstraction, where the ViewModel added nothing. On that day I decided I would never do that unless I have to.
3.I honestly see no harm in writing directly to the Model from the View, JUST SO LONG AS if the Model is InValid its data NEVER makes its way to the database. I honestly see no pro

A Generic Dialog ViewModel

I worked on a wpf viewmodel for dialogs, because it seemed strange to me that you needed for instance windows forms dialogs to open or save files in wpf. So I set about creating my own wpf dialogs. After creating the dialog viewmodels there still remained a small issue with the library and also I didn't have much time to write an article about it. I however published the library containing the viewmodels for dialogs with another article on my blog

MVC architecture in ASP.Net using C# and Microsoft Data Access Application block

The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes [Burbeck92]:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

Store and Display Images from MS Access Database Using C#

There is only the difference of coding syntax to stream the binary data of image content type to upload it into MS Access Database using C#/VB in ASP.Net 2.0

Namespaces required:-
using System.Data.OleDb;

OleDb is used to connect the web site forms with MS Access Database using Microsoft.Jet.OLEDB.4.0

ASP.Net Upload Image to MS Access Database

As you learnt from the previous articles to upload image to the SQL Database in ASP.Net 2.0 and stream that image into the memory to retrieve it from the database and display it on the web page. In this article you will learn how to upload images to the MS Access database in ASP.Net 2.0

First of all create an Access Database and place it in the App_Data folder of ASP.Net web site project. Then create a table "tblImg" with the following fields:

Wrong Account being used to access files - Help - No Impersonation


I run a simple .aspx website on a Windows Server 2008 machine.

There is NO impersonation, and System.Security.Principal.WindowsIdentity.GetCurrent().Name returns NT AUTHORITY\NETWORK SERVICE, which it the account which the application pool runs. In my web.config, I have <authentication mode="Forms">.


I tried to test the security of the application and server by removing file permissions to the .aspx files. I was greatly worried when the website continued to run without problem (it should not have been able to read the .aspx files).

By turning on file level auditing, I discovered that the .aspx files were being read by the machine$ account (if the machine is called Serv1, then the files would be read by the Serv1$ account, which seems to have access to all files on the local machine).


Is this a security breach or is this behaviour by design ?

Please can somebody assist, as I am worried.

Disallow Direct Access To Files



Here is my dilema, on my site i have a WordPress Audio player (http://wpaudioplayer.com/standalone) that plays my mp3's.

It loads the Mp3's in by javascript...example below:

       AudioPlayer.embed("audioplayer_7", { soundFile: "/Files/Music/[name of file].mp3" });

This file name is clearly visible in the browser source. Not a problem, however this means that any user can legitimately browse to the file directly and download it.

Now i still need the mp3 player (which is flash) to have access to the file but if a user was to try accessing the file directly, they would not be allowed access to it.

I am not sure how to go about this, i am circling the idea of a httphandler but not sure if this is sufficiant to stop the direct access to the file.

Any help would be appreciated

How to access a new database ( which i created ) in isqlplus ?



I created a new database with the help of Database Configuration Assistant !

I created with the scott account

Now i'm not able to connect to the database with the connect identifier with the scott account

The error i get is.,

ERROR - ORA-12154: TNS:could not resolve the connect identifier specified.

Plz help !

Access SessionState: via App1 to SessionState from App2


Hi .NET'ers,

i'm interested to do the following - i geuss, i have no option to do that:

we have our "mainapplication" on a DB; we are tracking user-login status by switching a bit in the DB in the users data row.

we hvae a second application, the backend, which is the administration tool.

(the applications are put in seperate diretories on HD)

sometimes, we need to block/ban users. in some cases the users are logged in, when we "see them in action".

i'd like to build a button in the backend-application, which logss-out the user from the mainapplication.

for sure: i can access the same DB and switch the bit to "know" he's offline, but this will not kill the session on the mainapplication.

because: if a user is on/offline is also indicated by the session in the IIS.
and as the IIS-session is active, the user may be already banned - but he will not be logged out automatically (and showing something like "you have been logged out because of a ban)

one option would be to call the DB by each page-load to find out, if the user is logged on.

is there any option to implement this?

Can I use MVVM for it?


I've read many articles about MVVM, but I can't get it into real code.

I have two lists which have common field user_id. First list contains all users with their names and second all files from all users. The asp.net page should show grid with newest file for every user. How can I get it into MVVM? Where should I bind username to his file? Need I ViewModel for every list or one common for both?


Regards, Gabriel

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend