本文整理汇总了C#中System.Windows.DependencyProperty类的典型用法代码示例。如果您正苦于以下问题:C# DependencyProperty类的具体用法?C# DependencyProperty怎么用?C# DependencyProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DependencyProperty类属于System.Windows命名空间,在下文中一共展示了DependencyProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetBindingObject
public static void SetBindingObject(FrameworkElement obj, BindingMode mode, object source, DependencyProperty dp, string propertyName)
{
Type propertyType = source.GetType().GetProperty(propertyName).PropertyType;
PropertyInfo info = source.GetType().GetProperty("RangeList");
FANumberRangeRule rangeRule = null;
if (info != null)
{
object value = info.GetValue(source, null);
if (value != null)
{
FALibrary.Utility.SerializableDictionary<string, FARange> dic =
(FALibrary.Utility.SerializableDictionary<string, FARange>)value;
if (dic.ContainsKey(propertyName))
{
rangeRule = new FANumberRangeRule(propertyType);
rangeRule.Range = dic[propertyName];
obj.Tag = rangeRule;
obj.Style = (Style)App.Current.Resources["TextBoxErrorStyle"];
}
}
}
Binding bd = new Binding(propertyName);
bd.Source = source;
bd.Mode = mode;
bd.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
if (rangeRule != null)
{
bd.NotifyOnValidationError = true;
bd.ValidationRules.Add(rangeRule);
}
obj.SetBinding(dp, bd);
}
示例2: SetBinding
internal static void SetBinding(this DependencyObject sourceObject, DependencyObject targetObject, DependencyProperty sourceProperty, DependencyProperty targetProperty)
{
Binding b = new Binding();
b.Source = sourceObject;
b.Path = new PropertyPath(sourceProperty);
BindingOperations.SetBinding(targetObject, targetProperty, b);
}
示例3: ImageButton
static ImageButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton),
new FrameworkPropertyMetadata(typeof(ImageButton)));
ImageButton.OrientationProperty = DependencyProperty.Register("Orientation", typeof(Orientation),
typeof(ImageButton), new FrameworkPropertyMetadata(Orientation.Horizontal,
FrameworkPropertyMetadataOptions.AffectsMeasure));
ImageButton.ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageButton),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender |
FrameworkPropertyMetadataOptions.AffectsMeasure));
ImageButton.IsToolStyleProperty = DependencyProperty.Register("IsToolStyle", typeof(bool), typeof(ImageButton),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender
| FrameworkPropertyMetadataOptions.AffectsArrange));
ImageButton.ContentHorizontalAlignmentProperty = DependencyProperty.Register(
"ContentHorizontalAlignment", typeof(HorizontalAlignment),
typeof(ImageButton), new FrameworkPropertyMetadata(HorizontalAlignment.Center,
FrameworkPropertyMetadataOptions.AffectsRender));
ImageButton.ContentVerticalAlignmentProperty = DependencyProperty.Register(
"ContentVerticalAlignment", typeof(VerticalAlignment),
typeof(ImageButton), new FrameworkPropertyMetadata(VerticalAlignment.Center,
FrameworkPropertyMetadataOptions.AffectsRender));
}
示例4: CoinFlipCounter
static CoinFlipCounter()
{
TossProperty = DependencyProperty.Register("Toss", typeof(Boolean), typeof(CoinFlipCounter), new PropertyMetadata(true));
Image1SourceProperty = DependencyProperty.Register("Image1Source", typeof(String), typeof(CoinFlipCounter), new PropertyMetadata(""));
Image2SourceProperty = DependencyProperty.Register("Image1Source", typeof(String), typeof(CoinFlipCounter), new PropertyMetadata(""));
}
示例5: ReplaceContent
/// <summary>
/// Replaces the content for a <see cref="DataField"/> with another control and updates the bindings.
/// </summary>
/// <param name="field">The <see cref="DataField"/> whose <see cref="TextBox"/> will be replaced.</param>
/// <param name="newControl">The new control you're going to set as <see cref="DataField.Content" />.</param>
/// <param name="dataBindingProperty">The control's property that will be used for data binding.</param>
/// <param name="bindingSetupFunction">
/// An optional <see cref="Action"/> you can use to change parameters on the newly generated binding before
/// it is applied to <paramref name="newControl"/>
/// </param>
/// <param name="sourceProperty">The source dependency property to use for the binding.</param>
public static void ReplaceContent(this DataField field, FrameworkElement newControl, DependencyProperty dataBindingProperty, Action<Binding> bindingSetupFunction, DependencyProperty sourceProperty)
{
if (field == null)
{
throw new ArgumentNullException("field");
}
if (newControl == null)
{
throw new ArgumentNullException("newControl");
}
// Construct new binding by copying existing one, and sending it to bindingSetupFunction
// for any changes the caller wants to perform
Binding newBinding = field.Content.GetBindingExpression(sourceProperty).ParentBinding.CreateCopy();
if (bindingSetupFunction != null)
{
bindingSetupFunction(newBinding);
}
// Replace field
newControl.SetBinding(dataBindingProperty, newBinding);
field.Content = newControl;
}
示例6: FocusScopeManager
static FocusScopeManager()
{
// Must do this explicitly because the default value of the FocusScopePriorityProperty depends on DefaultFocusScopePriority being properly initialized.
FocusScopeManager.DefaultFocusScopePriority = Int32.MaxValue;
FocusScopeManager.FocusScopePriorityProperty = DependencyProperty.RegisterAttached("FocusScopePriority", typeof(int), typeof(FocusScopeManager), new FrameworkPropertyMetadata(FocusScopeManager.DefaultFocusScopePriority, new PropertyChangedCallback(FocusScopeManager.FocusScopePriorityChanged)));
FocusManager.FocusedElementProperty.OverrideMetadata(typeof(FrameworkElement), new PropertyMetadata(null, null, new CoerceValueCallback(FocusScopeManager.FocusManager_CoerceFocusedElement)));
}
示例7: DependencyObjectPropertyDescriptor
/// <summary>
/// Creates a new dependency property descriptor. A note on perf: We don't
/// pass the property descriptor down as the default member descriptor here. Doing
/// so takes the attributes off of the property descriptor, which can be costly if they
/// haven't been accessed yet. Instead, we wait until someone needs to access our
/// Attributes property and demand create the attributes at that time.
/// </summary>
internal DependencyObjectPropertyDescriptor(DependencyProperty dp, Type ownerType)
: base(string.Concat(dp.OwnerType.Name, ".", dp.Name), null)
{
_dp = dp;
_componentType = ownerType;
_metadata = _dp.GetMetadata(ownerType);
}
示例8: OriginElement
public OriginElement()
{
FrameworkPropertyMetadata meta = new FrameworkPropertyMetadata();
meta.AffectsRender = true;
OriginProperty = DependencyProperty.Register("Origin", typeof(Point), typeof(OriginElement), meta);
}
示例9: GetStringValue
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Returns non-null string if this value can be converted to a string,
// null otherwise.
internal static string GetStringValue(DependencyProperty property, object propertyValue)
{
string stringValue = null;
// Special cases working around incorrectly implemented type converters
if (property == UIElement.BitmapEffectProperty)
{
return null; // Always treat BitmapEffects as complex value
}
if (property == Inline.TextDecorationsProperty)
{
stringValue = TextDecorationsFixup((TextDecorationCollection)propertyValue);
}
else if (typeof(CultureInfo).IsAssignableFrom(property.PropertyType)) //NumberSubstitution.CultureOverrideProperty
{
stringValue = CultureInfoFixup(property, (CultureInfo)propertyValue);
}
if (stringValue == null)
{
DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, propertyValue);
System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType);
Invariant.Assert(typeConverter != null);
if (typeConverter.CanConvertTo(context, typeof(string)))
{
stringValue = (string)typeConverter.ConvertTo(
context, System.Globalization.CultureInfo.InvariantCulture, propertyValue, typeof(string));
}
}
return stringValue;
}
示例10: WPFClickTypeWatch
static WPFClickTypeWatch()
{
DefaultStyleKeyProperty.OverrideMetadata( typeof( WPFClickTypeWatch ), new FrameworkPropertyMetadata( typeof( WPFClickTypeWatch ) ) );
ValueProperty = DependencyProperty.Register( "Value", typeof( int ), typeof( WPFClickTypeWatch ) );
DisabledColorProperty = DependencyProperty.Register( "DisabledColor", typeof( LinearGradientBrush ), typeof( WPFClickTypeWatch ) );
IsPausedProperty = DependencyProperty.Register( "IsPaused", typeof( bool ), typeof( WPFClickTypeWatch ) );
}
示例11: RichTextBlock
static RichTextBlock()
{
//This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
//This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(typeof(RichTextBlock), new FrameworkPropertyMetadata(typeof(RichTextBlock)));
InlineProperty = DependencyProperty.Register("RichText", typeof(List<Inline>), typeof(RichTextBlock), new PropertyMetadata(null, new PropertyChangedCallback(OnInlineChanged)));
}
示例12: ProvideValue
public override object ProvideValue(IServiceProvider serviceProvider)
{
var pvt = serviceProvider as IProvideValueTarget;
if (pvt == null)
{
return null;
}
_frameworkElement = pvt.TargetObject as FrameworkElement;
if (_frameworkElement == null)
{
return this;
}
_target = pvt.TargetProperty as DependencyProperty;
if (_target == null)
{
return this;
}
_frameworkElement.DataContextChanged += FrameworkElement_DataContextChanged;
var proxy = new Proxy();
var binding = new Binding()
{
Source = proxy,
Path = new PropertyPath("Value")
};
// Make sure we don't leak subscriptions
_frameworkElement.Unloaded += (e, v) => _subscription.Dispose();
return binding.ProvideValue(serviceProvider);
}
示例13: UpdateBinding
public static void UpdateBinding(this FrameworkElement instance, DependencyProperty prop)
{
var bindingExpression = instance.GetBindingExpression(prop);
if (bindingExpression != null)
bindingExpression.UpdateSource();
}
示例14: LixeiraProperty
static LixeiraProperty()
{
var metadata = new FrameworkPropertyMetadata((ImageSource)null);
ImageProperty = DependencyProperty.RegisterAttached("Image",
typeof(ImageSource),
typeof(LixeiraProperty), metadata);
}
示例15: DependencyPropertyChangedEventArgs
internal DependencyPropertyChangedEventArgs(
DependencyProperty property,
PropertyMetadata metadata,
bool isAValueChange,
EffectiveValueEntry oldEntry,
EffectiveValueEntry newEntry,
OperationType operationType)
{
_property = property;
_metadata = metadata;
_oldEntry = oldEntry;
_newEntry = newEntry;
_flags = 0;
_operationType = operationType;
IsAValueChange = isAValueChange;
// This is when a mutable default is promoted to a local value. On this operation mutable default
// value acquires a freezable context. However this value promotion operation is triggered
// whenever there has been a sub property change to the mutable default. Eg. Adding a TextEffect
// to a TextEffectCollection instance which is the mutable default. Since we missed the sub property
// change due to this add, we flip the IsASubPropertyChange bit on the following change caused by
// the value promotion to coalesce these operations.
IsASubPropertyChange = (operationType == OperationType.ChangeMutableDefaultValue);
}