本文整理汇总了C#中System.Windows.DependencyObject.ReadLocalValue方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.ReadLocalValue方法的具体用法?C# DependencyObject.ReadLocalValue怎么用?C# DependencyObject.ReadLocalValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DependencyObject
的用法示例。
在下文中一共展示了DependencyObject.ReadLocalValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBindingExp
static BindingExpression GetBindingExp(DependencyObject d, DependencyProperty dp) {
#if !SILVERLIGHT
return BindingOperations.GetBindingExpression(d, dp);
#else
if(d is FrameworkElement)
return ((FrameworkElement)d).GetBindingExpression(dp);
return d.ReadLocalValue(dp) as BindingExpression;
#endif
}
示例2: Generate
/// <summary>
/// Generates control fields
/// </summary>
/// <param name="source">The source.</param>
/// <param name="classType">Type of the class.</param>
/// <param name="method">The method.</param>
/// <param name="generateField">if set to <c>true</c> [generate field].</param>
/// <returns></returns>
public virtual CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod method, bool generateField)
{
DataGridColumn column = source as DataGridColumn;
string typeName = source.GetType().Name;
string name = ColumnName;
CodeExpression fieldReference = new CodeVariableReferenceExpression(name);
CodeTypeReference variableType = new CodeTypeReference(typeName);
CodeVariableDeclarationStatement declaration = new CodeVariableDeclarationStatement(variableType, name);
declaration.InitExpression = new CodeObjectCreateExpression(typeName);
method.Statements.Add(declaration);
if (CodeComHelper.IsValidForFieldGenerator(source.ReadLocalValue(DataGridColumn.WidthProperty)))
{
DataGridLength value = (DataGridLength)source.GetValue(DataGridColumn.WidthProperty);
if (value.UnitType == DataGridLengthUnitType.Pixel)
{
method.Statements.Add(new CodeAssignStatement(
new CodeFieldReferenceExpression(fieldReference, DataGridColumn.WidthProperty.Name),
new CodePrimitiveExpression((float)value.Value)));
}
}
CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, DataGridColumn.MaxWidthProperty);
CodeComHelper.GenerateFieldDoubleToFloat(method, fieldReference, source, DataGridColumn.MinWidthProperty);
CodeComHelper.GenerateEnumField<Visibility>(method, fieldReference, source, DataGridColumn.VisibilityProperty);
CodeComHelper.GenerateField<string>(method, fieldReference, source, DataGridColumn.SortMemberPathProperty);
UIElement header = column.Header as UIElement;
if (header != null)
{
TypeGenerator headerGenerator = new TypeGenerator();
CodeExpression headerExpr = headerGenerator.ProcessGenerators(header, classType, method, false);
method.Statements.Add(new CodeAssignStatement(
new CodeFieldReferenceExpression(fieldReference, "Header"), headerExpr));
}
else if (column.Header != null)
{
CodeComHelper.GenerateField<object>(method, fieldReference, source, DataGridColumn.HeaderProperty);
// TODO content can be another class, so this will not work
}
CodeComHelper.GenerateTemplateStyleField(classType, method, fieldReference, source, DataGridColumn.HeaderStyleProperty, name + "_h");
return fieldReference;
}
示例3: Generate
/// <summary>
/// Generates control fields
/// </summary>
/// <param name="source">The source.</param>
/// <param name="classType">Type of the class.</param>
/// <param name="method">The initialize method.</param>
/// <param name="generateField">if set to <c>true</c> [generate field].</param>
/// <returns></returns>
public override CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod method, bool generateField)
{
CodeExpression fieldReference = base.Generate(source, classType, method, generateField);
Path path = source as Path;
if (CodeComHelper.IsValidForFieldGenerator(source.ReadLocalValue(Path.DataProperty)))
{
CodeExpression dataValueExpression = CodeComHelper.GetValueExpression(classType, method, path.Data, path.Name + "_G");
method.Statements.Add(
new CodeAssignStatement(
new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(path.Name), "Data"),
dataValueExpression));
}
return fieldReference;
}
示例4: FindParentSettings
} // OnDependencyPropertyChanged
// ----------------------------------------------------------------------
private static ApplicationSettings FindParentSettings(DependencyObject element)
{
while (element != null)
{
ApplicationSettings applicationSettings = element.ReadLocalValue(ApplicationSettingsProperty) as ApplicationSettings;
if (applicationSettings != null)
{
return applicationSettings;
}
element = LogicalTreeHelper.GetParent(element);
}
return null;
} // FindParentSettings
示例5: GetObject
//-----------------------------------------------------
//
// Public Methods
//
//------------------------------------------------------
/// <summary> Returns the referenced object. </summary>
/// <param name="d">Element defining context for the reference. </param>
/// <param name="args">See ObjectRefArgs </param>
internal override object GetObject(DependencyObject d, ObjectRefArgs args)
{
if (d == null)
throw new ArgumentNullException("d");
object o = null;
if (args.ResolveNamesInTemplate)
{
// look in container's template (if any) first
FrameworkElement fe = d as FrameworkElement;
if (fe != null && fe.TemplateInternal != null)
{
o = Helper.FindNameInTemplate(_name, d);
if (args.IsTracing)
{
TraceData.Trace(TraceEventType.Warning,
TraceData.ElementNameQueryTemplate(
_name,
TraceData.Identify(d)));
}
}
if (o == null)
{
args.NameResolvedInOuterScope = true;
}
}
FrameworkObject fo = new FrameworkObject(d);
while (o == null && fo.DO != null)
{
DependencyObject scopeOwner;
o = fo.FindName(_name, out scopeOwner);
// if the original element is a scope owner, supports IComponentConnector,
// and has a parent, don't use the result of FindName. The
// element is probably an instance of a Xaml-subclassed control;
// we want to resolve the name starting in the next outer scope.
// (bug 1669408)
// Also, if the element's NavigationService property is locally
// set, the element is the root of a navigation and should use the
// inner scope (bug 1765041)
if (d == scopeOwner && d is IComponentConnector &&
d.ReadLocalValue(System.Windows.Navigation.NavigationService.NavigationServiceProperty) == DependencyProperty.UnsetValue)
{
DependencyObject parent = LogicalTreeHelper.GetParent(d);
if (parent == null)
{
parent = Helper.FindMentor(d.InheritanceContext);
}
if (parent != null)
{
o = null;
fo.Reset(parent);
continue;
}
}
if (args.IsTracing)
{
TraceData.Trace(TraceEventType.Warning,
TraceData.ElementNameQuery(
_name,
TraceData.Identify(fo.DO)));
}
if (o == null)
{
args.NameResolvedInOuterScope = true;
// move to the next outer namescope.
// First try TemplatedParent of the scope owner.
FrameworkObject foScopeOwner = new FrameworkObject(scopeOwner);
DependencyObject dd = foScopeOwner.TemplatedParent;
// if that doesn't work, we could be at the top of
// generated content for an ItemsControl. If so, use
// the (visual) parent - a panel.
if (dd == null)
{
Panel panel = fo.FrameworkParent.DO as Panel;
if (panel != null && panel.IsItemsHost)
{
dd = panel;
}
}
// next, see if we're in a logical tree attached directly
// to a ContentPresenter. This is the m---- equivalent of
//.........这里部分代码省略.........
示例6: HasTargetSet
///<summary>
/// Checks if the <see cref="ActionMessage"/>-Target was set.
///</summary>
///<param name="element">DependencyObject to check</param>
///<returns>True if Target or TargetWithoutContext was set on <paramref name="element"/></returns>
public static bool HasTargetSet(DependencyObject element)
{
return (element.ReadLocalValue(TargetProperty) != DependencyProperty.UnsetValue)
|| (element.ReadLocalValue(TargetWithoutContextProperty) != DependencyProperty.UnsetValue);
}
示例7: readSyncTypeDPValue
private static ScrollSyncType readSyncTypeDPValue(DependencyObject d, DependencyProperty dp)
{
var value = d.ReadLocalValue(dp);
return (value == DependencyProperty.UnsetValue ? ScrollSyncType.None : (ScrollSyncType)value);
}
示例8: IsTemplateDefined
/// <summary>
/// Check whether xxxTemplate property is set on the given element.
/// Only explicit local values or resource references count; data-bound or templated values don't count.
/// </summary>
internal static bool IsTemplateDefined(DependencyProperty templateProperty, DependencyObject d)
{
// Check whether xxxTemplate property is set on the given element.
object template = d.ReadLocalValue(templateProperty);
// the checks for UnsetValue and null are for perf:
// they're redundant to the type checks, but they're cheaper
return (template != DependencyProperty.UnsetValue &&
template != null &&
(template is FrameworkTemplate ||
template is ResourceReferenceExpression));
}
示例9: GenerateReadLocalValueTests
void GenerateReadLocalValueTests (DependencyObject widget, Type type)
{
DependencyProperty property;
FieldInfo[] fields;
Type ctype = type;
string method;
object retval;
while (ctype.IsSubclassOf (typeof (DependencyObject)) && !ctype.IsGenericType) {
fields = ctype.GetFields ();
bool emit_test = false;
for (int i = 0; i < fields.Length; i++) {
if (!fields[i].IsPublic || !fields[i].IsStatic || fields[i].FieldType != typeof (DependencyProperty))
continue;
try {
property = fields[i].GetValue (null) as DependencyProperty;
} catch {
property = null;
}
if (property == null)
continue;
emit_test = true;
break;
}
if (emit_test) {
EmitTestMethod (type, "ReadLocalValue_" + PrettyName(ctype), true);
for (int i = 0; i < fields.Length; i++) {
if (!fields[i].IsPublic || !fields[i].IsStatic || fields[i].FieldType != typeof (DependencyProperty))
continue;
try {
property = fields[i].GetValue (null) as DependencyProperty;
} catch {
property = null;
}
if (property == null)
continue;
method = "ReadLocalValue(" + ctype.Name + "." + fields[i].Name + ")";
try {
retval = widget.ReadLocalValue (property);
sb.AppendLine (" retval = widget." + method + ";");
if (retval != DependencyProperty.UnsetValue) {
if (retval != null) {
sb.AppendLine (" Assert.IsNotNull(retval, \"" + method + " should not have returned null\");");
AssertValuesEqual (widget, type, method, "retval", retval, true);
} else {
sb.AppendLine (" Assert.IsNull(retval, \"" + method + " should have returned null\");");
}
} else {
sb.AppendLine (" Assert.AreEqual(DependencyProperty.UnsetValue, retval, \"" + method +
" should not have a value by default\");");
}
} catch (Exception ex) {
sb.AppendLine (" // [MoonlightBug] - Moonlight needs to be fixed to throw on some ReadLocalValue invocations");
sb.AppendLine (" //Assert.Throws<" + ex.GetType ().Name + ">(delegate {");
sb.AppendLine (" // retval = widget." + method + ";");
sb.AppendLine (" //}, \"" + method + " should thow an exception\");");
}
}
sb.AppendLine (" }");
sb.AppendLine ();
}
ctype = ctype.BaseType;
}
}
示例10: HasDragsWindowEnabled
/// <summary>
/// Determines whether or not a DependencyObject has the WindowMovement.DragsWindow property set to true.
/// </summary>
/// <param name="visual">The DependencyObject to test for the property on.</param>
/// <returns>true if the object has the attached property and it is set to true.</returns>
public static bool HasDragsWindowEnabled(DependencyObject visual)
{
var dragsWindow = visual.ReadLocalValue(DragsWindow);
return (dragsWindow != DependencyProperty.UnsetValue && (bool) dragsWindow);
}
示例11: ApplyItemContainerStyle
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
private void ApplyItemContainerStyle(DependencyObject container, object item)
{
FrameworkObject foContainer = new FrameworkObject(container);
// don't overwrite a locally-defined style (bug 1018408)
if (!foContainer.IsStyleSetFromGenerator &&
container.ReadLocalValue(FrameworkElement.StyleProperty) != DependencyProperty.UnsetValue)
{
return;
}
// Control's ItemContainerStyle has first stab
Style style = ItemContainerStyle;
// no ItemContainerStyle set, try ItemContainerStyleSelector
if (style == null)
{
if (ItemContainerStyleSelector != null)
{
style = ItemContainerStyleSelector.SelectStyle(item, container);
}
}
// apply the style, if found
if (style != null)
{
// verify style is appropriate before applying it
if (!style.TargetType.IsInstanceOfType(container))
throw new InvalidOperationException(SR.Get(SRID.StyleForWrongType, style.TargetType.Name, container.GetType().Name));
foContainer.Style = style;
foContainer.IsStyleSetFromGenerator = true;
}
else if (foContainer.IsStyleSetFromGenerator)
{
// if Style was formerly set from ItemContainerStyle, clear it
foContainer.IsStyleSetFromGenerator = false;
container.ClearValue(FrameworkElement.StyleProperty);
}
}
示例12: IsTemplateSelectorDefined
internal static bool IsTemplateSelectorDefined(DependencyProperty templateSelectorProperty, DependencyObject d)
{
object obj = d.ReadLocalValue(templateSelectorProperty);
return obj != DependencyProperty.UnsetValue && obj != null && (obj is DataTemplateSelector);// || obj is ResourceReferenceExpression);
}
示例13: CopyBrushes
private void CopyBrushes(DependencyObject dst, DependencyObject src)
{
if (src != null && dst != null && src.GetType() == dst.GetType())
{
Type type = dst.GetType();
BindingFlags bindingFlag = BindingFlags.Static | BindingFlags.Public;
if (typeof (Polygon).IsAssignableFrom(type))
{
bindingFlag = bindingFlag | BindingFlags.FlattenHierarchy;
}
FieldInfo[] fields = type.GetFields(bindingFlag);
for (int i = 0; i < fields.Length; i++)
{
DependencyProperty value = fields[i].GetValue(null) as DependencyProperty;
if (value != null)
{
Brush brush = src.ReadLocalValue(value) as Brush;
if (brush != null)
{
dst.SetValue(value, brush);
}
}
}
if (src is Border && dst is Border)
{
CopyBrushes(((Border) dst).Child, ((Border) src).Child);
return;
}
if (src is Panel && dst is Panel)
{
UIElementCollection children = ((Panel) src).Children;
UIElementCollection uIElementCollections = ((Panel) dst).Children;
if (children.Count == uIElementCollections.Count)
{
for (int j = 0; j < children.Count; j++)
{
CopyBrushes(uIElementCollections[j], children[j]);
}
}
}
}
}
示例14: GetBindingPaths
private static IEnumerable<string> GetBindingPaths(DependencyObject element)
{
var properties = GetDependencyProperties(element);
foreach (var property in properties)
{
var expression = element.ReadLocalValue(property) as BindingExpression;
if(expression != null &&
expression.ParentBinding != null &&
expression.ParentBinding.Path != null)
yield return expression.ParentBinding.Path.Path;
}
}
示例15: GenerateSetStringValueTests
//.........这里部分代码省略.........
sb.AppendLine (" }, \"" + method.Replace ("\"","\\\"") + " should thow an exception\");");
}
// Then we check that the value is what we we just set
method = "GetValue(" + ctype.Name + "." + prop_name + ")";
try {
retval = widget.GetValue (property);
actual = retval as string;
sb.AppendLine (" retval = widget." + method + ";");
if (actual == "some text") {
sb.AppendLine (" Assert.AreEqual(\"some text\", retval, \"" + method + " should have returned 'some text'\");");
} else if (actual != null) {
sb.AppendLine (" Assert.AreEqual(\"" + actual + "\", retval, \"" + method + " should have returned '" + actual + "'\");");
} else {
sb.AppendLine (" Assert.IsNull(retval, \"" + method + " should have returned null\");");
}
} catch (Exception ex) {
sb.AppendLine (" Assert.Throws<" + ex.GetType ().Name + ">(delegate {");
sb.AppendLine (" retval = widget." + method + ";");
sb.AppendLine (" }, \"" + method + " should thow an exception\");");
}
// Next we try setting the string to null to see if it will let us
method = "SetValue(" + ctype.Name + "." + prop_name + ", null)";
try {
widget.SetValue (property, null);
sb.AppendLine (" widget." + method + ";");
} catch (Exception ex) {
sb.AppendLine (" Assert.Throws<" + ex.GetType ().Name + ">(delegate {");
sb.AppendLine (" widget." + method + ";");
sb.AppendLine (" }, \"" + method + " should thow an exception\");");
}
// Then we check that the value was actually set to null as opposed to String.Empty
method = "GetValue(" + ctype.Name + "." + prop_name + ")";
try {
retval = widget.GetValue (property);
actual = retval as string;
sb.AppendLine (" retval = widget." + method + ";");
if (actual == String.Empty) {
sb.AppendLine (" Assert.AreEqual(String.Empty, retval, \"" + method + " should have returned String.Empty\");");
} else if (actual != null) {
sb.AppendLine (" Assert.AreEqual(\"" + actual + "\", retval, \"" + method + " should have returned '" + actual + "'\");");
} else {
sb.AppendLine (" Assert.IsNull(retval, \"" + method + " should have returned null\");");
}
} catch (Exception ex) {
sb.AppendLine (" Assert.Throws<" + ex.GetType ().Name + ">(delegate {");
sb.AppendLine (" retval = widget." + method + ";");
sb.AppendLine (" }, \"" + method + " should thow an exception\");");
retval = actual = null;
}
// If the GetValue returned String.Empty, then we need to check ReadLocalValue to see wtf is going on
if (actual == String.Empty) {
method = "ReadLocalValue(" + PrettyName (ctype) + "." + prop_name + ")";
try {
retval = widget.ReadLocalValue (property);
sb.AppendLine (" retval = widget." + method + ";");
if (retval != DependencyProperty.UnsetValue) {
actual = retval as string;
if (actual == String.Empty) {
sb.AppendLine (" Assert.AreEqual(String.Empty, retval, \"" + method + " should have returned String.Empty\");");
} else if (actual != null) {
sb.AppendLine (" Assert.AreEqual(\"" + actual + "\", retval, \"" + method + " should have returned '" + actual + "'\");");
} else {
sb.AppendLine (" Assert.IsNull(retval, \"" + method + " should have returned null\");");
}
} else {
sb.AppendLine (" Assert.AreEqual(DependencyProperty.UnsetValue, retval, \"" + method +
" should not have a value by default\");");
}
} catch (Exception ex) {
sb.AppendLine (" // [MoonlightBug] - Moonlight needs to be fixed to throw on some ReadLocalValue invocations");
sb.AppendLine (" //Assert.Throws<" + ex.GetType ().Name + ">(delegate {");
sb.AppendLine (" // retval = widget." + method + ";");
sb.AppendLine (" //}, \"" + method + " should thow an exception\");");
}
}
}
sb.AppendLine (" }");
sb.AppendLine ();
}
ctype = ctype.BaseType;
}
}