void ContentControl3D_Loaded(object sender, RoutedEventArgs e) { // Inject the ContentControl3D into the ViewModel object, so that it // knows which control the RotateCommand should target. ContentControl3D cc3D = sender as ContentControl3D; ThingViewModel thing = cc3D.DataContext as ThingViewModel; if (thing != null) { thing.CommandTarget = cc3D; } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // This horrendous hack is necessary because the Content/BackContent of a ContentControl3D // is a logical child of the ContentControl3D, not the ContentPresenters that host the content. // In order to inform the Content/BackContent elements of which side they reside on, we must // attach the IsOnFrontSide property value to them via a value converter that is set on the // TemplateBinding of the ContentPresenters' Content property. If we do not do this, then the // IsOnFrontSide property value does not get inherited by the elements shown in the control. // This is important when BringIntoView is called on an element in the ContentControl3D and we // need to figure out on which side of the control it exists. This workaround is only for // the Content and BackContent, but not the elements created by the ContentTemplate or // BackContentTemplate properties. DependencyObject depObj = value as DependencyObject; string side = parameter as string; if (depObj != null && !String.IsNullOrEmpty(side)) { bool?isOnFrontSide = side == "FRONT"; ContentControl3D.SetIsOnFrontSide(depObj, isOnFrontSide); } return(value); }
void OnListBoxItemUnselected(object sender, RoutedEventArgs e) { // When the user brings a new ListBoxItem to the front of the 3D scene // it becomes the selected item in the ListBox. At that time, we must // verify that the previously selected item's front side is facing forward. DependencyObject depObj = e.OriginalSource as DependencyObject; while (depObj != null) { if (VisualTreeHelper.GetChildrenCount(depObj) == 0) { break; } depObj = VisualTreeHelper.GetChild(depObj, 0); ContentControl3D cc3D = depObj as ContentControl3D; if (cc3D != null) { cc3D.BringFrontSideIntoView(); break; } } }