| Цитата(HellMasterHaiL @ 23.1.2009, 12:18) | Здравствуйте. Только начинаю знакомиться с Silverlight'ом, так что простите за глупый вопрос. Необходимо динамически создатья в Canvas объект Rectangle. Перепробовал разные вариант, не получается... где-то что-то не догоняю(
|
| Код | //твоя процедура Rectangle rec1 = new Rectangle(); rec1.Fill = CreateFadeBrush(Color.FromArgb(255, 255, 255, 255), Color.FromArgb(255, 16, 213, 255)); //вдруг пораскрашивать захочешь rec1.StrokeThickness = 1; rec1.Tag = "Yourtag"; rec1.Cursor = Cursors.Hand; rec1.SetValue(Rectangle.NameProperty, (string)("RecName")); rec1.SetValue(Canvas.TopProperty, (double)10); rec1.SetValue(Canvas.LeftProperty, (double)20); rec1.SetValue(Rectangle.WidthProperty, (double)100); rec1.SetValue(Rectangle.HeightProperty, (double)200); YourCanvas.Children.Add( rec1);
|
| Код | private static LinearGradientBrush CreateFadeBrush(Color StartColor, Color EndColor) { LinearGradientBrush br = new LinearGradientBrush(); br.EndPoint = new Point(0.5, 1); br.StartPoint = new Point(0.5, 0); GradientStop gstop1 = new GradientStop(); gstop1.Color = StartColor; br.GradientStops.Add(gstop1); GradientStop gstop2 = new GradientStop(); gstop2.Color = EndColor; gstop2.Offset = 1; br.GradientStops.Add(gstop2); return br; }
|
|