- MigrateToMvvmMef-Part2_Src.zip
- MigrateToMvvmMef-Part2_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part3_Src.zip
- MigrateToMvvmMef-Part3_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- AnotherXap.Models
- AnotherXap.ViewModels
- AnotherXap.Views
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- SaveState
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part1_Src.zip
- MigrateToMvvmMef-Part1_Src
- ProductApp.Common
- ProductApp.Main
- ProductApp.sln
- ProductApp.suo
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ProductApp.Views
{
public partial class AddProductWindow : ChildWindow
{
public AddProductWindow(IEnumerable<string> categories)
{
InitializeComponent();
Categories = categories;
categoryList.ItemsSource = this.Categories;
categoryList.IsEnabled = false;
OKButton.IsEnabled = false;
}
public string ProductName { get; set; }
public decimal Price { get; set; }
public IEnumerable<string> Categories { get; set; }
public string SelectedCategory { get; set; }
public event EventHandler AddEvent;
private void OKButton_Click(object sender, RoutedEventArgs e)
{
ProductName = productName.Text;
if (System.Text.RegularExpressions.Regex.IsMatch(unitPrice.Text, @"^-?\d*[0-9]?(|.\d*[0-9]|,\d*[0-9])?$"))
{
Price = Convert.ToDecimal(unitPrice.Text);
}
else
{
MessageBox.Show("Invalid Price");
unitPrice.Background = new SolidColorBrush(Colors.Red);
return;
}
SelectedCategory = this.categoryList.SelectedItem as string;
DialogResult = true;
AddEvent(this, new EventArgs());
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
private void productName_TextChanged(object sender, TextChangedEventArgs e)
{
CheckForOKButton();
}
private void unitPrice_TextChanged(object sender, TextChangedEventArgs e)
{
CheckForOKButton();
}
private void unitPrice_GotFocus(object sender, RoutedEventArgs e)
{
unitPrice.Background = new SolidColorBrush(Colors.White);
}
private void categoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
CheckForOKButton();
}
private void CheckForOKButton()
{
if (productName.Text == "" || unitPrice.Text == "" || categoryList.SelectedIndex < 1)
{
OKButton.IsEnabled = false;
}
else
{
OKButton.IsEnabled = true;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Shenwei is a software developer and architect, and has been working on business applications using Microsoft and Oracle technologies since 1996. He obtained Microsoft Certified Systems Engineer (MCSE) in 1998 and Microsoft Certified Solution Developer (MCSD) in 1999. He has experience in ASP.NET, C#, Visual Basic, Windows and Web Services, Silverlight, WPF, JavaScript/AJAX, HTML, SQL Server, and Oracle.