The most useful advantage of using keyword is that is it calls the Dispose() method automatically to release the resources and also automatically implements the try catch blocks for you.Here it is called a using statement.So the advantage is that we don't have to explicitly write a try-catch block and our code looks small.
Popular Posts
-
In this article we will discuss about Arraylist, Hash table, Sorted list and Dictionary. Arraylist: - This is one type of Array whose size...
-
Due to security reason we can't upload file to server using HTTP, so best solution is to use FTP for the same. Below is the complete ...
-
When attempting to install SAP Crystal Reports for Visual Studio 2012 , the installation fails with the following message: Error 2753....
-
Start the visual studio and create a WPF application. Make a ViewModelBase class and inherite the InotifyPropertyChanged interface. ...
-
https://sandbox.google.com/checkout/sell/ https://www.secpay.com/java-bin/services/SECCardService?wsdl
-
window.onbeforeunload = function (evt) { var showmessage = 'Are you sure you want to leave?'; if (typeof evt == 'undef...
-
private Tuple<int, int> GetScreenResolution() { var contents = Application.Current.Host.Content; bool wasFullScreen = contents.IsFull...
-
Public Class clsCrypto Private bytIV() As Byte = {121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62} Private Cons...
-
For load Random Images var arrName = new Array(2); arrName[0] = "http://abc.com/1.png" ; arrName[1] = " ...
-
Edit record from Gridview in ASP.Net using RowEditingg Event. protected void Gridview1 _RowEditing(object sender, GridViewEditEventArgs e)...
Wednesday, February 8, 2012
Sunday, February 5, 2012
MassageBox in WPF Application with MVVM
Start the visual studio and
create a WPF application.
Make a ViewModelBase
class and inherite the InotifyPropertyChanged interface.
Create a new method in “ViewModelBase”
class for show the message like -
public void MessageBoxShow(string message)
{
MessageBox.Show(message, "",
MessageBoxButton.OK, MessageBoxImage.Error);
}
After create a Helper class in helper folder name
is BaseCommand and Inharite/implement the Icommand Interface.
Like-
internal class BaseCommand : ICommand
{
private readonly
Action _command;
private readonly Func<bool>
_canExecute;
public BaseCommand(Action
command, Func<bool>
canExecute = null)
{
if (command == null)
throw new
ArgumentNullException("command");
_canExecute = canExecute;
_command = command;
}
public void Execute(object parameter)
{
_command();
}
public bool
CanExecute(object parameter)
{
if (_canExecute == null)
return true;
return _canExecute();
}
public event EventHandler CanExecuteChanged;
}
After create a class (EmployeViewModel) in ViewModel folder and inherite the “ViewModelBase” class
and add namespace the Basecommand class.
Like-
using WPF_MVVM_MessageBox.Helper;
Create a private method in “EmployeViewModel” class for save
the data and call the MessageBoxShow method.
private void Save()
{
//here code for Save the Data
MessageBoxShow("Data Save Successfully.");
}
Create a Icommand type property in “EmployeViewModel” class and
add the Save method for Execute
Like-
public ICommand
ClickCommand { get { return
new BaseCommand(Save);
} }
Finally add the reference of ViewModel directory in
XAML window.
Like-
xmlns:me="clr-namespace:WPF_MVVM_MessageBox.ViewModels" Title="Create Employee" Height="400" Width="400"
After create a Window resource in XAML file.
Like-
<Window.Resources>
<me:EmployeeViewModel x:Key="viewModel"
/>
</Window.Resources>
Add a button in XAML file.
Like-
<Button Height="50" Width="100" Content="Click
Me" Name="btnnew" Command="{Binding Source={StaticResource viewModel}, Path= ClickCommand}"
/>
and bind the button command to “ClickCommand”
property.
Finally Run the Application and click on button
cheer.
Labels:
Dialogbox in WPF,
MessageBox in WPF,
MVVM Messagebox,
WPF
Location:
New Delhi, Delhi, India
Subscribe to:
Posts (Atom)