2011-10-12 84 views
0

有一個非常老的WPF應用程序超樹 - http://blogs.msdn.com/b/llobo/archive/2007/10/31/mindmap-app-using-hyperbolic-tree.aspx在Silverlight中轉換WPF控件

的源代碼可以在codeplax.com找到 - http://hypertree.codeplex.com/releases/view/11524

我想用我的Silverlight應用程序這棵樹的控制。現在的問題是我對silverlight是新手,並且代碼使用了一些WPF特定的東西。

請建議我解決我的問題。

在此先感謝。

阿比納夫

更新:

之類的東西 FrameworkPropertyMetadataFrameworkPropertyMetadataOptionsInvalidateVisual()OnRender覆蓋,孩子UIElements

程式碼:

public class SmartBorder : Decorator 
{ 
    #region Dependency Properties 
    public static readonly DependencyProperty GlowBrushProperty = 
     DependencyProperty.Register("GlowBrush", typeof(Brush), typeof(SmartBorder), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); 

    ...... 

    #region Dependency Property backing CLR properties 
...... 
    #endregion 

    // if the button is pressed, this fires 
    private static void OnRenderIsPressedChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) 
    { 
     SmartBorder border = o as SmartBorder; 
     if (border != null) 
     { 
      if ((bool)e.NewValue == true) 
      { 
       border.BorderBrush = Brushes.Transparent; 
       border.BorderWidth = 2; 
      } 
      else 
      { 
       border.BorderBrush = Brushes.Red; 
       border.BorderWidth = 2; 

      } 
      border.InvalidateVisual(); 
     } 
    } 

    // if the mouse is over the control, this fires 
    private static void OnRenderIsMouseOverChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) 
    { 
     SmartBorder border = o as SmartBorder; 
     if (border != null) 
     { 
      border.InvalidateVisual(); 
     } 

    } 

    // a series of methods which all make getting the default or currently selected brush easier 


    protected override void OnRender(DrawingContext dc) 
    { 
     Rect rc = new Rect(0, 0, this.ActualWidth, this.ActualHeight); 

     LinearGradientBrush gradientOverlay = GetGradientOverlay(); 
     Brush glowBrush = GetGlowBrush(); 
     Brush backBrush = GetBackgroundBrush(); 
     Brush borderBrush = GetBorderBrush(); 
     Pen borderPen = new Pen(borderBrush, BorderWidth); 
     double cornerRadiusCache = CornerRadius; 

     // draw the highlight as necessary 
     if (RenderIsMouseOver) 
     { 
      Rect rcGlow = rc; 
      double glowMove = BorderWidth * 2; 
      rcGlow.Inflate(glowMove, glowMove); 
      glowMove = 0; 
      rcGlow.Offset(new Vector(glowMove, glowMove)); 
      dc.DrawRoundedRectangle(GetOuterGlowBrush(), null, rcGlow, cornerRadiusCache, cornerRadiusCache); 
     } 

     // we want to clip anything that might errantly draw outside of the smart border control 
     dc.PushClip(new RectangleGeometry(rc, cornerRadiusCache, cornerRadiusCache)); 

     dc.DrawRoundedRectangle(backBrush, borderPen, rc, cornerRadiusCache, cornerRadiusCache); 
     dc.DrawRoundedRectangle(gradientOverlay, borderPen, rc, cornerRadiusCache, cornerRadiusCache); 

     if (!RenderIsPressed) 
     { 
      double clipBorderSize = BorderWidth * -4.0; 
      Rect rcClip = rc; 
      rcClip.Offset(clipBorderSize, clipBorderSize); 
      rcClip.Inflate(-clipBorderSize, -clipBorderSize); 
      dc.PushClip(new RectangleGeometry(rcClip, cornerRadiusCache, cornerRadiusCache)); 
      dc.DrawEllipse(glowBrush, null, new Point(this.ActualWidth/2, this.ActualHeight * 0.10), this.ActualWidth * 0.80, this.ActualHeight * 0.40); 
      dc.Pop(); 
     } 
     // just draw the border now to make sure it overlaps everything nicely 
     dc.DrawRoundedRectangle(null, borderPen, rc, cornerRadiusCache, cornerRadiusCache); 

     dc.Pop(); 
     //base.OnRender(drawingContext); 
    } 


    protected override Size MeasureOverride(Size constraint) 
    { 
     UIElement child = this.Child as UIElement; 

     double borderThickness = BorderWidth * 2.0; 

     if (child != null) 
     { 

    ... 
     } 

     return new Size(Math.Min(borderThickness, constraint.Width), Math.Min(borderThickness, constraint.Height)); 
    } 
} 
+0

的 「WPF一些具體的事情,」 請詳細說明下WPF_Compatibility解決方案。 =) – Jens

+0

@Jens代碼已添加。 –

+0

'幫助你'是指解釋這些東西是什麼? ... :-) ...以及你必須閱讀man ... MSDN/Blogs/silverlight文章...因爲我們可能會給你簡潔的定義,但是它們會讓你的生活更加艱難,因爲他們可能會提到一些條款你可能不會進一步知道.... BTW歡迎來到WPF/Silverlight的具有挑戰性但美妙的世界.... :-) –

回答

1

關於FrameworkPropertyMetadataFrameworkPropertyMetadataOptions和價值的強制等爲Silverlight看到ClipFlair代碼庫(http://clipflair.codeplex.com

+0

使用強制代碼來自DrWPF博客 –

+0

您還可以在https://www.dropbox.com/sh/oq6x074fx1y4cev/AACF96fWv4kJvuW1eSV0Dwdxa上看到我在編寫WPF_Compatibility時收集的參考資料 –