本文整理汇总了C#中System.Windows.Data.BindingExpressionBase.ValidateWithoutUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# BindingExpressionBase.ValidateWithoutUpdate方法的具体用法?C# BindingExpressionBase.ValidateWithoutUpdate怎么用?C# BindingExpressionBase.ValidateWithoutUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了BindingExpressionBase.ValidateWithoutUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Window1
//引入命名空间
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace BindingExpressionBaseValidateWithoutUpdating
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
// Create an object and set it to the window's DataContext.
LibraryItem item = new LibraryItem("Enter the title",
"Enter the call number", DateTime.Now + new TimeSpan(14, 0, 0, 0));
this.DataContext = item;
}
// Check whether the call number is valid when the
// TextBox loses foces.
private void CallNum_LostFocus(object sender, RoutedEventArgs e)
{
BindingExpression be = CallNum.GetBindingExpression(TextBox.TextProperty);
be.ValidateWithoutUpdate();
}
// Show the validation error when one occurs.
private void CallNum_Error(object sender, ValidationErrorEventArgs e)
{
if (e.Action == ValidationErrorEventAction.Added)
{
MessageBox.Show(e.Error.ErrorContent.ToString());
}
}
// Update the source data object when the user clicks
// the submit button.
private void Button_Click(object sender, RoutedEventArgs e)
{
BindingExpression be = CallNum.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();
}
}
}
示例2: LibraryItem
//引入命名空间
using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Globalization;
namespace BindingExpressionBaseValidateWithoutUpdating
{
// LibraryItem implements INotifyPropertyChanged so that the
// application is notified when a property changes. It
// implements IEditableObject so that pending changes can be discarded.
// In this example, the application does not discard changes.
public class LibraryItem : INotifyPropertyChanged, IEditableObject
{
struct ItemData
{
internal string Title;
internal string CallNumber;
internal DateTime DueDate;
}
ItemData copyData;
ItemData currentData;
public LibraryItem(string title, string callNum, DateTime dueDate)
{
Title = title;
CallNumber = callNum;
DueDate = dueDate;
}
public string Title
{
get { return currentData.Title; }
set
{
if (currentData.Title != value)
{
currentData.Title = value;
NotifyPropertyChanged("Title");
}
}
}
public string CallNumber
{
get { return currentData.CallNumber; }
set
{
if (currentData.CallNumber != value)
{
currentData.CallNumber = value;
NotifyPropertyChanged("CallNumber");
}
}
}
public DateTime DueDate
{
get { return currentData.DueDate; }
set
{
if (value != currentData.DueDate)
{
currentData.DueDate = value;
NotifyPropertyChanged("DueDate");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
#region IEditableObject Members
public virtual void BeginEdit()
{
copyData = currentData;
}
public virtual void CancelEdit()
{
currentData = copyData;
NotifyPropertyChanged("");
}
public virtual void EndEdit()
{
copyData = new ItemData();
}
#endregion
}
public class CallNumberRule : ValidationRule
{
// A valid call number contains a period (.)
// and 6 characters after the period.
public override ValidationResult Validate(object value,
CultureInfo cultureInfo)
{
string callNum = (string)value;
int dotIndex = callNum.IndexOf(".");
if (dotIndex == -1 || dotIndex == 0)
{
return new ValidationResult(false,
"There must be characters followed by a period (.) in the call number.");
}
string substr = callNum.Substring(dotIndex + 1);
if (substr.Length != 6)
{
return new ValidationResult(false,
"The call number must have 6 characters after the period (.).");
}
return ValidationResult.ValidResult;
}
}
}