本文整理汇总了C#中INotifyPropertyChanged类的典型用法代码示例。如果您正苦于以下问题:C# INotifyPropertyChanged类的具体用法?C# INotifyPropertyChanged怎么用?C# INotifyPropertyChanged使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
INotifyPropertyChanged类属于命名空间,在下文中一共展示了INotifyPropertyChanged类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PropertyChangedIsCalled
/// <summary>
/// Asserts that property changed is called for the specified property when the value of the property is set
/// to the specified value.
/// </summary>
/// <param name="observableObject">The object that will be observed.</param>
/// <param name="propertyName">The name of the property that will be observed.</param>
/// <param name="value">The value to which the property should be set.</param>
/// <param name="isRaised">Determines wether property changed should be called or not.</param>
private static void PropertyChangedIsCalled(
INotifyPropertyChanged observableObject,
string propertyName,
object value,
bool isRaised)
{
var propertyFound = false;
var propertyChangedCalled = false;
observableObject.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == propertyName)
{
propertyChangedCalled = true;
}
};
var properties = observableObject.GetType().GetProperties();
foreach (var propertyInfo in properties)
{
if (propertyInfo.Name == propertyName)
{
propertyInfo.SetValue(observableObject, value, null);
propertyFound = true;
break;
}
}
Assert.IsTrue(
propertyFound,
string.Format("The property {0} could not be found on object {1}.", propertyName, observableObject));
Assert.AreEqual(isRaised, propertyChangedCalled);
}
示例2: BindingContext
public BindingContext(
INotifyPropertyChanged propertyMotherToWatch,
Func<PropertyChangedEventHandler> propertyEventProvider)
{
_PropertyMother = propertyMotherToWatch;
_PropertyEventProvider = propertyEventProvider;
}
示例3: ValidationTemplate
public ValidationTemplate(INotifyPropertyChanged target)
{
this.target = target;
validator = GetValidator(target.GetType());
validationResult = validator.Validate(target);
target.PropertyChanged += Validate;
}
示例4: SubscriptionTree
internal SubscriptionTree(INotifyPropertyChanged parameter, List<SubscriptionNode> children)
{
this.Parameter = parameter;
this.Children = children;
SubscribeToEntireTree(this.Children);
}
示例5: AddHandler
/// <summary>
/// Add a handler for the given source's event.
/// </summary>
public static void AddHandler(INotifyPropertyChanged source, EventHandler<PropertyChangedEventArgs> handler, string propertyName)
{
if (handler == null)
throw new ArgumentNullException("handler");
CurrentManager.PrivateAddHandler(source, handler, propertyName);
}
示例6: ClearPropertyBinding
/// <summary>
/// Clears the property binding.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <param name="sourceProp">The source prop.</param>
/// <param name="targetProp">The target prop.</param>
public static void ClearPropertyBinding(Object source, INotifyPropertyChanged target, string sourceProp, string targetProp)
{
WeakEntry entry = new WeakEntry(source.GetType(), target.GetType(), sourceProp, targetProp);
Delegate setAction = GetExpressionAction(entry, source, true);
WeakSource.UnRegister(source, setAction, targetProp);
}
示例7: TestNotifyPropertyChanged
public TestNotifyPropertyChanged(INotifyPropertyChanged model,
string expectedPropertyName = null)
{
m_Model = model;
m_Model.PropertyChanged += OnPropertyChanged;
m_ExpectedPropertyName = expectedPropertyName;
}
示例8: OnAssociatedObjectLoaded
protected virtual void OnAssociatedObjectLoaded()
{
var frameworkElement = ((FrameworkElement) AssociatedObject);
frameworkElement.DataContextChanged += OnDataContextChanged;
_expression = GetBindingExpressionToValidate(frameworkElement);
_viewModel = frameworkElement.DataContext as INotifyPropertyChanged;
var triggerValidate = (ITriggerValidate) _viewModel;
if (triggerValidate != null)
{
_canValidate = triggerValidate.CanValidate;
triggerValidate.CanValidateChanged += () =>
{
_canValidate = triggerValidate.CanValidate;
Refresh();
};
}
else
{
throw new InvalidOperationException("The view model must implement the ITriggerValidate interface");
}
HookPropertyChangedAndRefresh();
}
示例9: StartWatching
private void StartWatching(INotifyPropertyChanged npc)
{
if (npc == null) throw new ArgumentNullException("npc");
PropertyChangedEventManager.AddListener(npc,
new WeakEventListener((t, o, arg) => Console.WriteLine("PropertyChanged event: Type: {0}, Sender: {1}, EventArgs: {2}",t,o,arg)),
string.Empty);
}
示例10: Bind
public static Action Bind(this UISwitch toggle, INotifyPropertyChanged source, string propertyName)
{
var property = source.GetProperty(propertyName);
if (property.PropertyType == typeof(bool))
{
toggle.SetValue(source, property);
var handler = new PropertyChangedEventHandler ((s, e) =>
{
if (e.PropertyName == propertyName)
{
toggle.InvokeOnMainThread(()=>
toggle.SetValue(source, property));
}
});
source.PropertyChanged += handler;
var valueChanged = new EventHandler(
(sender, e) => property.GetSetMethod().Invoke (source, new object[]{ toggle.On }));
toggle.ValueChanged += valueChanged;
return new Action(() =>
{
source.PropertyChanged -= handler;
toggle.ValueChanged -= valueChanged;
});
}
else
{
throw new InvalidCastException ("Binding property is not boolean");
}
}
示例11: DependencyObserver
/// <summary>
/// Initializes a new instance of the <see cref="DependencyObserver"/> class.
/// </summary>
/// <param name="messageHandler">The message handler.</param>
/// <param name="methodFactory">The method factory.</param>
/// <param name="notifier">The notifier.</param>
public DependencyObserver(IRoutedMessageHandler messageHandler, IMethodFactory methodFactory, INotifyPropertyChanged notifier)
{
_messageHandler = messageHandler;
_methodFactory = methodFactory;
_notifier = notifier;
_singlePathObservers = new Dictionary<string, SinglePropertyPathObserver>();
}
示例12: DependencyObserver
/// <summary>
/// Initializes a new instance of the <see cref="DependencyObserver"/> class.
/// </summary>
/// <param name="messageHandler">The message handler.</param>
/// <param name="methodFactory">The method factory.</param>
/// <param name="notifier">The notifier.</param>
public DependencyObserver(IRoutedMessageHandler messageHandler, IMethodFactory methodFactory, INotifyPropertyChanged notifier)
{
_messageHandler = messageHandler;
_methodFactory = methodFactory;
_weakNotifier = new WeakReference<INotifyPropertyChanged>(notifier);
_monitoringInfos = new Dictionary<string, MonitoringInfo>();
}
示例13: RemoveHandler
private static void RemoveHandler(INotifyPropertyChanged dataContext)
{
if (dataContext == null || !Handlers.ContainsKey(dataContext)) return;
dataContext.PropertyChanged -= Handlers[dataContext].PropertyChanged;
Handlers.Remove(dataContext);
}
示例14: BindToText
/// <summary>
/// Creates a custom binding for the <see cref="TextView"/>.
/// Remember to call <see cref="IMvxViewBindingManager.UnbindView"/> on the view after you're done
/// using it.
/// </summary>
public static void BindToText(this TextView view, INotifyPropertyChanged source,
string sourcePropertyName, IMvxValueConverter converter = null,
object converterParameter = null)
{
var activity = view.Context as IMvxBindingActivity;
if (activity == null)
return;
var description = new MvxBindingDescription
{
SourcePropertyPath = sourcePropertyName,
Converter = converter,
ConverterParameter = converterParameter,
TargetName = "Text",
Mode = MvxBindingMode.OneWay
}.ToEnumerable();
var tag = view.GetBindingTag ();
if (tag != null) {
MvxBindingTrace.Trace(
MvxTraceLevel.Warning,
"Replacing binding tag for a TextView " + view.Id);
}
view.SetBindingTag (new MvxViewBindingTag (description));
activity.BindingManager.BindView (view, source);
}
示例15: RemoveListener
public static void RemoveListener(INotifyPropertyChanged source, IWeakEventListener listener)
{
if (source == null) { throw new ArgumentNullException("source"); }
if (listener == null) { throw new ArgumentNullException("listener"); }
PropertyChangedEventManager.CurrentManager.ProtectedRemoveListener(source, listener);
}