/// <summary> /// Checks to see if the item being injected implements the IDockAware interface and creates the necessary data bindings. /// </summary> /// <remarks> /// First we will check if the ContentPane.Content property implements the IDockAware interface. Depending on the type of item being injected, /// this may be a View or a ViewModel. If no IDockAware interface is found to create a binding, we next move to the ContentPane.DataContext property, which will /// most likely be a ViewModel. /// </remarks> /// <param name="container"></param> void CreateDockAwareBindings(ContentPane contentPane) { Binding binding = new Binding("Header"); //let's first check the item that was injected for IDockAware. This may be a View or ViewModel var dockAwareContent = contentPane.Content as IDockAware; if (dockAwareContent != null) { binding.Source = dockAwareContent; if (dockAwareContent.Image != null) { Binding imageBinding = new Binding("Image"); imageBinding.Converter = new ResourceTypeToIconConverter(); imageBinding.Source = dockAwareContent; contentPane.SetBinding(ContentPane.ImageProperty, imageBinding); } } //nothing was found on the item being injected, let's check the DataContext if (binding.Source == null) { //fall back to data context of the content pane, which is most likely a ViewModel var dockAwareDataContext = contentPane.DataContext as IDockAware; if (dockAwareDataContext != null) { binding.Source = dockAwareDataContext; } } contentPane.SetBinding(HeaderedContentControl.HeaderProperty, binding); }
/// <summary> /// Invoked when a ContentPane for a given item is being removed. /// </summary> /// <param name="cp">The pane being removed</param> protected virtual void RemovePane(ContentPane cp) { // we need to temporarily change the close action while we close it DependencyProperty closeProp = ContentPane.CloseActionProperty; if (cp == null) { return; } object oldValue = cp.ReadLocalValue(closeProp); BindingExpressionBase oldExpression = cp.GetBindingExpression(closeProp); cp.CloseAction = PaneCloseAction.RemovePane; // restore the original close action if (oldExpression != null) { cp.SetBinding(closeProp, oldExpression.ParentBindingBase); } else if (oldValue == DependencyProperty.UnsetValue) { cp.ClearValue(closeProp); } else { cp.SetValue(closeProp, oldValue); } cp.PreviewMouseDown -= PaneOnPreviewMouseDown; }
protected virtual void RemovePane(ContentPane cp) { var closeProp = ContentPane.CloseActionProperty; if (cp == null) { return; } var oldValue = cp.ReadLocalValue(closeProp); BindingExpressionBase oldExpression = cp.GetBindingExpression(closeProp); cp.CloseAction = PaneCloseAction.RemovePane; if (oldExpression != null) { cp.SetBinding(closeProp, oldExpression.ParentBindingBase); } else if (oldValue == DependencyProperty.UnsetValue) { cp.ClearValue(closeProp); } else { cp.SetValue(closeProp, oldValue); } cp.PreviewMouseDown -= PaneOnPreviewMouseDown; }
/// <summary> /// Invoked when a ContentPane for a given item is being removed. /// </summary> /// <param name="cp">The pane being removed</param> protected virtual void RemovePane(ContentPane cp) { // we need to temporarily change the close action while we close it DependencyProperty closeProp = ContentPane.CloseActionProperty; if(cp == null) { return; } object oldValue = cp.ReadLocalValue(closeProp); BindingExpressionBase oldExpression = cp.GetBindingExpression(closeProp); cp.CloseAction = PaneCloseAction.RemovePane; // restore the original close action if(oldExpression != null) { cp.SetBinding(closeProp, oldExpression.ParentBindingBase); } else if(oldValue == DependencyProperty.UnsetValue) { cp.ClearValue(closeProp); } else { cp.SetValue(closeProp, oldValue); } }