本文整理汇总了C#中IDataDescriptor.Attach方法的典型用法代码示例。如果您正苦于以下问题:C# IDataDescriptor.Attach方法的具体用法?C# IDataDescriptor.Attach怎么用?C# IDataDescriptor.Attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataDescriptor
的用法示例。
在下文中一共展示了IDataDescriptor.Attach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindingDependency
/// <summary>
/// Creates a new <see cref="BindingDependency"/> object.
/// </summary>
/// <param name="sourceDd">Souce data descriptor for the dependency.</param>
/// <param name="targetDd">Target data descriptor for the dependency.</param>
/// <param name="autoAttachToSource">If set to <c>true</c>, the new dependency object will be
/// automatically attached to the <paramref name="sourceDd"/> data descriptor. This means it will
/// capture changes from it and reflect them on the <paramref name="targetDd"/> data descriptor.</param>
/// <param name="updateSourceTrigger">This parameter controls, which target object event makes this
/// binding dependency copy the target value to the <paramref name="sourceDd"/> data descriptor.
/// If set to <see cref="UpdateSourceTrigger.PropertyChanged"/>, the new binding dependency object
/// will automatically attach to property changes of the <paramref name="targetDd"/> data descriptor and
/// reflect the changed value to the <paramref name="sourceDd"/> data descriptor. If set to
/// <see cref="UpdateSourceTrigger.LostFocus"/>, the new binding dependency will attach to the
/// <see cref="UIElement.EventOccured"/> event of the <paramref name="parentUiElement"/> object.
/// If set to <see cref="UpdateSourceTrigger.Explicit"/>, the new binding dependency won't attach to
/// the target at all.</param>
/// <param name="parentUiElement">The parent <see cref="UIElement"/> of the specified <paramref name="targetDd"/>
/// data descriptor. This parameter is only used to attach to the lost focus event if
/// <paramref name="updateSourceTrigger"/> is set to <see cref="UpdateSourceTrigger.LostFocus"/>.</param>
/// <param name="customValueConverter">Set a custom value converter with this parameter. If this parameter
/// is set to <c>null</c>, the default <see cref="TypeConverter"/> will be used.</param>
/// <param name="customValueConverterParameter">Parameter to be used in the custom value converter, if one is
/// set.</param>
public BindingDependency(IDataDescriptor sourceDd, IDataDescriptor targetDd, bool autoAttachToSource,
UpdateSourceTrigger updateSourceTrigger, UIElement parentUiElement,
IValueConverter customValueConverter, object customValueConverterParameter)
{
_sourceDd = sourceDd;
_targetDd = targetDd;
_targetObject = _targetDd.TargetObject as DependencyObject;
_sourceObject = _sourceDd.TargetObject as DependencyObject;
_valueConverter = customValueConverter;
_converterParameter = customValueConverterParameter;
if (autoAttachToSource && sourceDd.SupportsChangeNotification)
{
sourceDd.Attach(OnSourceChanged);
_attachedToSource = true;
}
if (targetDd.SupportsChangeNotification)
{
if (updateSourceTrigger == UpdateSourceTrigger.PropertyChanged)
{
targetDd.Attach(OnTargetChanged);
_attachedToTarget = true;
}
else if (updateSourceTrigger == UpdateSourceTrigger.LostFocus)
{
if (parentUiElement != null)
parentUiElement.EventOccured += OnTargetElementEventOccured;
_attachedToLostFocus = parentUiElement;
}
}
// Initially update endpoints
if (autoAttachToSource)
UpdateTarget();
if (updateSourceTrigger != UpdateSourceTrigger.Explicit &&
!autoAttachToSource) // If we are attached to both, only update one direction
UpdateSource();
}
示例2: InitializeSubItemsSource
/// <summary>
/// Initializes the <see cref="ItemsControl.ItemsSource"/> property with the <see cref="SubItemsProvider"/>.
/// </summary>
/// <returns><c>true</c>, if the <see cref="ItemsControl.ItemsSource"/> property was changed by this method, else <c>false</c>.</returns>
protected virtual bool InitializeSubItemsSource()
{
SubItemsProvider sip = SubItemsProvider;
IEnumerable oldItemsSource = ItemsSource;
if (!_contextChangedAttached)
{
ContextChanged += OnContextChanged;
_contextChangedAttached = true;
}
if (_attachedContextSource != null)
_attachedContextSource.Detach(OnDataContextValueChanged);
_attachedContextSource = DataContext.EvaluatedSourceValue;
_attachedContextSource.Attach(OnDataContextValueChanged);
object context = Context;
if (context == null)
return false;
ItemsSource = sip == null ? null : sip.GetSubItems(context);
if (oldItemsSource == ItemsSource)
return false;
MPF.TryCleanupAndDispose(oldItemsSource);
CheckExpandable();
return true;
}
示例3: AttachToSource
/// <summary>
/// Attaches a change handler to the specified data descriptor
/// <paramref name="source"/>, which will be used as binding source.
/// </summary>
protected void AttachToSource(IDataDescriptor source)
{
if (source != null && source.SupportsChangeNotification)
{
_attachedSource = source;
_attachedSource.Attach(OnBindingSourceChange);
}
}