示例#1
0
        public ThemedWindow()
        {
            this.ShouldBeThemed();

            WindowStyle = WindowStyle.None;
            ResizeMode = ResizeMode.CanResizeWithGrip;
            Background = Brushes.Transparent;
            AllowsTransparency = true;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            ShowInTaskbar = false;

            Grid host = new Grid();
            //Header
            host.RowDefinitions.Add(new RowDefinition
            {
                Height = GridLength.Auto
            });
            //Body
            host.RowDefinitions.Add(new RowDefinition());

            FrameworkElement header = BuildHeaderArea();
            header.SetValue(Grid.RowProperty, 0);
            host.Children.Add(header);

            ContentPresenter contentPresenter = new ContentPresenter();
            contentPresenter.SetValue(Grid.RowProperty, 1);
            contentPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding
            {
                Mode = BindingMode.OneWay,
                RelativeSource = new RelativeSource
                {
                    Mode = RelativeSourceMode.FindAncestor,
                    AncestorType = typeof(ThemedWindow)
                },
                Path = new PropertyPath("Content")
            });
            contentPresenter.Resources = Resources;
            host.Children.Add(contentPresenter);

            host.SetResourceReference(BackgroundProperty, EnvironmentColors.ToolWindowBackgroundBrushKey);

            Border hostContainer = new Border
            {
                Child = host,
                //Margin = new Thickness(1, 1, 5, 5),
                BorderThickness = new Thickness(1)
            };
            hostContainer.SetResourceReference(BorderBrushProperty, EnvironmentColors.MainWindowActiveDefaultBorderBrushKey);
            //hostContainer.Effect = new DropShadowEffect
            //{
            //    Direction = -75,
            //    ShadowDepth = 2,
            //    BlurRadius = 2,
            //    Color = Colors.Azure
            //};

            base.Content = hostContainer;
        }
        public DragContentAdorner(UIElement adornedElement, object draggedData, DataTemplate dataTemplate, Point offset)
            : base(adornedElement)
        {
            _contentPresenter = new ContentPresenter {
                Content = draggedData,
                ContentTemplate = dataTemplate,
                Opacity = 0.7
            };

            _translate = new TranslateTransform { X = 0, Y = 0 };
            _contentPresenter.RenderTransform = _translate;

            _offset = offset;

            Host.Children.Add(_contentPresenter);

            _contentPresenter.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Left);
            _contentPresenter.SetValue(VerticalAlignmentProperty, VerticalAlignment.Top);
        }
示例#3
0
        protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            Storyboard oldStoryboard = OldContentStoryboard;
            Storyboard newStoryboard = NewContentStoryboard;

            if (oldStoryboard != null || newStoryboard != null)
            {
                oldContent.Style = OldContentStyle;
                newContent.Style = NewContentStyle;

                // Flag to determine when both storyboards are done
                bool done = oldStoryboard == null || newStoryboard == null;

                if (oldStoryboard != null)
                {
                    oldStoryboard = oldStoryboard.Clone();
                    oldContent.SetValue(OldContentStoryboardProperty, oldStoryboard);
                    oldStoryboard.Completed += delegate
                    {
                        if (done)
                            EndTransition(transitionElement, oldContent, newContent);
                        done = true;
                    };
                    oldStoryboard.Begin(oldContent, true);
                }

                if (newStoryboard != null)
                {
                    newStoryboard = newStoryboard.Clone();
                    newContent.SetValue(NewContentStoryboardProperty, newStoryboard);
                    newStoryboard.Completed += delegate
                    {
                        if (done)
                            EndTransition(transitionElement, oldContent, newContent);
                        done = true;
                    };
                    newStoryboard.Begin(newContent, true);
                }
            }
            else
            {
                EndTransition(transitionElement, oldContent, newContent);
            }
        }
示例#4
0
文件: Slider.cs 项目: senfo/snaglV2
        /// <summary>
        /// 
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        FrameworkElement CreateTickMark(Point start, Point end, TickLocation location)
        {
            // If no template was specified, use the default
                if (TickTemplate == null)
                {
                    System.Windows.Shapes.Line ln = new System.Windows.Shapes.Line();
                    ln.Stroke = new SolidColorBrush(Colors.Black);
                    ln.StrokeThickness = 1.0;
                    ln.X1 = start.X;
                    ln.Y1 = start.Y;
                    ln.X2 = end.X;
                    ln.Y2 = end.Y;

                    return ln;
                }
                else
                {
                    ContentPresenter cp = new ContentPresenter();
                    //cp.Content = "a";
                    cp.ContentTemplate = TickTemplate;

                    if (location == TickLocation.Top)
                    {
                        cp.SetValue(Canvas.TopProperty, start.Y - cp.ActualHeight);
                        cp.SetValue(Canvas.LeftProperty, start.X - (cp.ActualWidth / 2));
                    }
                    else
                    {
                        cp.SetValue(Canvas.TopProperty, end.Y);
                        cp.SetValue(Canvas.LeftProperty, start.X - (cp.ActualWidth / 2));
                    }

                    return cp;
                }
        }
示例#5
0
 private void AddTickmark(double position)
 {
     ContentPresenter c = new ContentPresenter();
     c.SetValue(PositionProperty, position);
     c.SetBinding(ContentPresenter.ContentTemplateProperty, new System.Windows.Data.Binding()
     {
         Source = this,
         BindsDirectlyToSource = true,
         Path = new PropertyPath("TickMarkTemplate")
     });
     Children.Add(c);
 }
示例#6
0
文件: Graph.cs 项目: edealbag/bot
 private static void SetIsCenter(ContentPresenter element, bool value)
 {
     element.SetValue(IsCentersCenterPropertyKey, value);
 }
示例#7
0
    private static void CreateDragAdorner(DropInfo dropInfo)
    {
      var template = GetDragAdornerTemplate(m_DragInfo.VisualSource);
      var templateSelector = GetDragAdornerTemplateSelector(m_DragInfo.VisualSource);

      UIElement adornment = null;

      var useDefaultDragAdorner = GetUseDefaultDragAdorner(m_DragInfo.VisualSource);
      var useVisualSourceItemSizeForDragAdorner = GetUseVisualSourceItemSizeForDragAdorner(m_DragInfo.VisualSource);

      if (template == null && templateSelector == null && useDefaultDragAdorner) {
        var bs = CaptureScreen(m_DragInfo.VisualSourceItem, m_DragInfo.VisualSourceFlowDirection);
        if (bs != null) {
          var factory = new FrameworkElementFactory(typeof(Image));
          factory.SetValue(Image.SourceProperty, bs);
          factory.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
          factory.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
          factory.SetValue(FrameworkElement.WidthProperty, bs.Width);
          factory.SetValue(FrameworkElement.HeightProperty, bs.Height);
          factory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
          factory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
          template = new DataTemplate { VisualTree = factory };
        }
      }

      if (template != null || templateSelector != null) {
        if (m_DragInfo.Data is IEnumerable && !(m_DragInfo.Data is string)) {
          if (!useDefaultDragAdorner && ((IEnumerable)m_DragInfo.Data).Cast<object>().Count() <= 10) {
            var itemsControl = new ItemsControl();
            itemsControl.ItemsSource = (IEnumerable)m_DragInfo.Data;
            itemsControl.ItemTemplate = template;
            itemsControl.ItemTemplateSelector = templateSelector;

            if (useVisualSourceItemSizeForDragAdorner)
            {
              var bounds = VisualTreeHelper.GetDescendantBounds(m_DragInfo.VisualSourceItem);
              itemsControl.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
            }

            // The ItemsControl doesn't display unless we create a grid to contain it.
            // Not quite sure why we need this...
            var grid = new Grid();
            grid.Children.Add(itemsControl);
            adornment = grid;
          }
        } else {
          var contentPresenter = new ContentPresenter();
          contentPresenter.Content = m_DragInfo.Data;
          contentPresenter.ContentTemplate = template;
          contentPresenter.ContentTemplateSelector = templateSelector;

          if (useVisualSourceItemSizeForDragAdorner)
          {
            var bounds = VisualTreeHelper.GetDescendantBounds(m_DragInfo.VisualSourceItem);
            contentPresenter.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
            contentPresenter.SetValue(FrameworkElement.MinHeightProperty, bounds.Height);
          }

          adornment = contentPresenter;
        }
      }

      if (adornment != null) {
        if (useDefaultDragAdorner) {
          adornment.Opacity = GetDefaultDragAdornerOpacity(m_DragInfo.VisualSource);
        }

        var rootElement = RootElementFinder.FindRoot(dropInfo.VisualTarget ?? m_DragInfo.VisualSource);
        DragAdorner = new DragAdorner(rootElement, adornment);
      }
    }
示例#8
0
        private void Render()
        {
            ColumnDefinitions.Clear();
            Children.Clear();

            if (ItemsSource == null) return;

            var i = 0;
            foreach (var item in ItemsSource)
            {
                var valueProperty = item.GetType().GetProperty(ValueMemberPath);
                var value = valueProperty != null ? (int)valueProperty.GetValue(item, null) : 1;

                var column = new ColumnDefinition {Width = new GridLength(value, GridUnitType.Star)};
                ColumnDefinitions.Add(column);

                var bar = new ContentPresenter {ContentTemplate = ItemTemplate, Content = item};
                Children.Add(bar);
                bar.SetValue(ColumnProperty, i);
                i++;
            }
        }
示例#9
0
 FrameworkElement CreateTick(Point start, Point end)
 {
     if (TickTemplate == null) {
         Line ln = new Line();
         ln.SetBinding(Line.StrokeProperty, new System.Windows.Data.Binding("Foreground"));
         ln.StrokeThickness = 1.0;
         ln.X1 = start.X;
         ln.Y1 = start.Y;
         ln.X2 = end.X;
         ln.Y2 = end.Y;
         return ln;
     } else {
         ContentPresenter cp = new ContentPresenter();
         cp.Content = "a";
         cp.ContentTemplate = TickTemplate;
         cp.SetValue(Canvas.TopProperty, (IsHorizontal ? start.Y : start.Y - cp.ActualHeight / 2 ));
         cp.SetValue(Canvas.LeftProperty, (IsHorizontal ? start.X - cp.ActualWidth / 2 : start.X));
         return cp;
     }
     //return null;
 }
 public static void SetRefreshTriggerBinding(ContentPresenter element, bool value)
 {
     element.SetValue(RefreshTriggerBindingProperty, value);
 }