/// <summary> /// Returns the node view containing the given view model. /// </summary> /// <param name="pItem">The item contained by the view.</param> /// <returns>The found view if any, null otherwise.</returns> public AGraphItem GetContainerForViewModel(IGraphItemViewModel pItem) { GraphItemContainer lItemView = this.ItemContainerGenerator.ContainerFromItem(pItem) as GraphItemContainer; if (lItemView != null) { return(lItemView.TemplateControl); } return(null); }
/// <summary> /// Method called when the control content changed. /// </summary> /// <param name="pOldContent">The previous content.</param> /// <param name="pNewContent">The new content.</param> protected override void OnContentChanged(object pOldContent, object pNewContent) { base.OnContentChanged(pOldContent, pNewContent); BindingOperations.ClearAllBindings(this); // The content is the view model. IGraphItemViewModel lNewContent = pNewContent as IGraphItemViewModel; if (lNewContent != null) { // Setting the style. this.Style = lNewContent.ContainerStyle; // Binding the IsSelected property. Binding lIsSelectedBinding = new Binding("IsSelected") { Source = lNewContent, Mode = BindingMode.TwoWay }; this.SetBinding(GraphItemContainer.IsSelectedProperty, lIsSelectedBinding); // Binding the ZIndex property. Binding lZIndexBinding = new Binding("ZIndex") { Source = lNewContent, Mode = BindingMode.OneWay }; this.SetBinding(GraphItemContainer.ZIndexProperty, lZIndexBinding); if (lNewContent is IPositionable) { // Binding the X position. Binding lXBinding = new Binding("X") { Source = lNewContent, Mode = BindingMode.TwoWay }; this.SetBinding(GraphItemContainer.PosXProperty, lXBinding); // Binding the Y position. Binding lYBinding = new Binding("Y") { Source = lNewContent, Mode = BindingMode.TwoWay }; this.SetBinding(GraphItemContainer.PosYProperty, lYBinding); } } }