private static void CreateAndSetElementNameBinding(string propertyName, SceneNode node, Action <BindingSceneNode> setValue) { string description = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertyChangeUndoDescription, new object[1] { (object)propertyName }); SceneViewModel viewModel = node.ViewModel; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(description)) { node.EnsureNamed(); editTransaction.Update(); BindingSceneNode bindingSceneNode = viewModel.CreateSceneNode(PlatformTypes.Binding) as BindingSceneNode; bindingSceneNode.ElementName = node.Name; setValue(bindingSceneNode); editTransaction.Commit(); } }
public bool IsBindingLegal(SceneNode targetElement, ReferenceStep targetProperty, out string errorMessage) { errorMessage = string.Empty; string pathOrXpath = this.PathOrXPath; if (this.SupportsElementName && this.ElementName != null && targetElement.Name == this.ElementName || this.ElementBindingTarget == targetElement) { if (pathOrXpath.Length == 0) { errorMessage = StringTable.BindingPropertyToDefiningElementError; return(false); } if (pathOrXpath == targetProperty.Name) { errorMessage = StringTable.BindingPropertyToSelfError; return(false); } } bool flag = false; if (targetProperty.Attributes.Matches((Attribute)BindingSceneNode.contentCategory)) { flag = true; } if (ContentPresenterElement.ContentProperty.Equals((object)targetProperty)) { flag = true; } if (flag && (this.SupportsElementName && this.ElementName != null || this.ElementBindingTarget != null)) { string visualTarget = (string)null; if (BindingSceneNode.DoesVisualPropertyEvaluateToVisual(pathOrXpath, out visualTarget)) { errorMessage = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.BindingVisualToVisualError, (object)targetProperty.Name, (object)targetElement.TargetType.Name, (object)visualTarget); return(false); } } return(true); }