2010-07-13 13 views
7

के भीतर एलीप्स स्थिति जोड़ें मेरे पास एक अंडाकार है जिसे मैं प्रोग्रामेटिक रूप से कैनवास में रखना चाहता हूं। दुर्भाग्यवश, अंडाकार केवल ऊपरी दाएं भाग में खींचता है। कोई मदद?कैनवास

SolidColorBrush newColor = HotSquare(col); 
     Color newCol = getCol(col); 
     Color newCol2 = getCol2(col); 

     Ellipse el1 = new Ellipse(); 
     el1.Height = 40; 
     el1.Width = 40; 
     RadialGradientBrush rgb = new RadialGradientBrush(); 
     GradientStop gsa = new GradientStop(); 
     el1.StrokeThickness = 3; 
     el1.Stroke = newColor; 
     el1.StrokeDashArray = new DoubleCollection() { 6, 6 }; 
     gsa.Color = newCol; 
     gsa.Offset = 0; 
     rgb.GradientStops.Add(gsa); 
     GradientStop gsb = new GradientStop(); 
     gsb.Color = newCol2; 
     gsb.Offset = 1; 
     rgb.GradientStops.Add(gsb); 
     el1.Fill = rgb; 

     Ellipse el2 = new Ellipse(); 
     el2.Height = 40; 
     el2.Width = 40; 
     el2.StrokeThickness = 3; 
     el2.Stroke = newColor; 

     //el2.Fill = new SolidColorBrush(Colors.Transparent); 

     Canvas canvas = new Canvas(); 
     canvas.Children.Add(el1); 
     //canvas.Children.Add(el2); 
     TextBlock txt = new TextBlock(); 
     txt.Text = "\n " + amnt.ToString(); 
     txt.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); 
     txt.Height = 60; 
     txt.Width = 60; 
     txt.HorizontalAlignment = HorizontalAlignment.Center; 
     //txt.VerticalAlignment = VerticalAlignment.Bottom; 
     txt.FontSize = 12; 
     canvas.Children.Add(txt); 
     Border border = new Border(); 
     border.BorderBrush = newColor; 
     border.BorderThickness = new Thickness(2); 
     border.Child = canvas; 
     LocationRect lr = new LocationRect(North, West, South, East); 
     HotspotLayer.AddChild(ele, lr); 
+0

क्या कोई कारण है कि आप Xaml में इसका वर्णन नहीं कर रहे हैं? – AnthonyWJones

+3

क्योंकि मैं उन्हें प्रोग्रामिक रूप से जोड़ रहा हूं, एक्सएएमएल का कोई प्रत्यक्ष हेरफेर इस तरह नहीं (केवल रनटाइम पर)। –

उत्तर

11

आप कैनवास में अपनी स्थिति को स्थापित करने के लिए बच्चे के तत्व पर Canvas.SetTop और Canvas.SetLeft कॉल कर सकते हैं।

Canvas.SetTop(el2, 100); 
Canvas.SetLeft(el2, 100);