Example #1
0
        private void scrollViewer_Loaded(object sender, RoutedEventArgs e)
        {
            scrollViewer.Loaded -= scrollViewer_Loaded;
            scrollViewer.ViewChanged += ScrollViewer_ViewChanged;

            currentTopGroupHeader = this.scrollViewer.FindDescendantByName("TopGroupHeader") as ContentControl;
            Binding binding = new Binding();
            binding.Source = this;
            binding.Mode = BindingMode.OneWay;
            binding.Path = new PropertyPath("GroupHeaderTemplate");
            currentTopGroupHeader.SetBinding(ContentControl.ContentTemplateProperty, binding);
            currentTopGroupHeader.Visibility = Visibility.Collapsed;
            if (scrollViewer.VerticalOffset == 0)
            {
                CreateVisual();
            }
            else
            {
                scrollViewer.RegisterPropertyChangedCallback(ScrollViewer.VerticalOffsetProperty, new DependencyPropertyChangedCallback(OnScrollViewerVerticalOffsetChanged));
            }
        }
Example #2
0
        /// <summary>
        /// Update the selected value of the of the TreeView based on the value
        /// of the currently selected TreeViewItem and the SelectedValuePath.
        /// </summary>
        /// <param name="item">
        /// Value of the currently selected TreeViewItem.
        /// </param>
        private void UpdateSelectedValue(object item)
        {
            if (item != null)
            {
                string path = SelectedValuePath;
                if (string.IsNullOrEmpty(path))
                {
                    SelectedValue = item;
                }
                else
                {
                    // Since we don't have the ability to evaluate a
                    // BindingExpression, we'll just create a new temporary
                    // control to bind the value to which we can then copy out
                    Binding binding = new Binding
                                      {
                                          Path = new PropertyPath(path),
                                          Source = item
                                      };
                    ContentControl temp = new ContentControl();
                    temp.SetBinding(ContentControl.ContentProperty, binding);
                    SelectedValue = temp.Content;

                    // Remove the Binding once we have the value (this is
                    // especially important if the value is a UIElement because
                    // it should not exist in the visual tree once we've
                    // finished)
                    temp.ClearValue(ContentControl.ContentProperty);
                }
            }
            else
            {
                ClearValue(SelectedValueProperty);
            }
        }
        public async Task ControlWithExistingBindingOnContentWithNullValueThrows()
        {
            await ExecuteOnUIThread(() =>
                {
                    var control = new ContentControl();
                    Binding binding = new Binding
                    {
                        Path = new PropertyPath("ObjectContents"),
                        Source = new SimpleModel() { ObjectContents = null }
                    };
                    control.SetBinding(ContentControl.ContentProperty, binding);

                    IRegionAdapter adapter = new TestableContentControlRegionAdapter();

                    Assert.ThrowsException<InvalidOperationException>(
                        () => (MockPresentationRegion)adapter.Initialize(control, "Region1"),
                        "ContentControl's Content property is not empty.");
                });
        }
Example #4
0
 private static void ContentChanged(ContentControl control, IPropertyChangedArgs<string> args)
 {
     control.SetBinding(ContentControl.ContentProperty, args.NewValue);
 }
Example #5
0
 private Control CreateControl(object content)
 {
     var control = new ContentControl
     {
         Content = content,
         RenderTransformOrigin = new Point(0.5, 0.5)
     };
     control.SetBinding(ContentControl.ContentTemplateProperty, new Binding { Source = this, Path = new PropertyPath("ItemTemplate") });
     return control;
 }
Example #6
0
 private ContentControl CreateGroupHeader(IGroupHeader group)
 {
     ContentControl groupheader = new ContentControl();
     Binding binding = new Binding();
     binding.Source = this;
     binding.Mode = BindingMode.OneWay;
     binding.Path = new PropertyPath("GroupHeaderTemplate");
     groupheader.SetBinding(ContentControl.ContentTemplateProperty, binding);
     groupheader.DataContext = group;
     groupheader.HorizontalAlignment = HorizontalAlignment.Stretch;
     groupheader.HorizontalContentAlignment = HorizontalAlignment.Stretch;
     groupheader.VerticalAlignment = VerticalAlignment.Top;
     groupheader.VerticalContentAlignment = VerticalAlignment.Stretch;
     return groupheader;
 }