2012-02-17 3 views
0

Silverlight에서 .cs 파일의 선형 그래디언트 변수가있는 타원을 채우려고합니다. 여기에 제가 시도한 것이 있습니다 ...Silverlight에서 .cs 파일의 타원 채우기

 newEllipse.Fill = ballBG; 

그러나 이것은 이미 타원에있는 채우기를 제거합니다. 나는 또한이 오류와 함께 온다, 그러나 ...

 newEllipse.Background = ballBG; 

을 시도 ... 'System.Windows.Shapes.Ellipse' '배경'없이 확장 메서드 '배경'수용에 대한 정의가 포함되어 있지 않습니다 'System.Windows.Shapes.Ellipse'유형의 첫 번째 인수를 찾을 수 있습니다 (사용 지시문 또는 어셈블리 참조가 누락 되었습니까?)

어떻게해야합니까?

+1

무슨 행동 기대하니? –

+0

'Ellipse'에는'Background' 속성이 없습니다. 또한,'ballBG'는 어떤 타입입니까? – ken2k

+0

LinearGradientBrush ballBG = new LinearGradientBrush(); –

답변

0

SolidColorBrush 가진 경우 :이 적혀있는 LinearGradientBrush를 들어

Ellipse redEllipse = new Ellipse(); 
redEllipse.Height = 100; 
redEllipse.Width = 300;   
SolidColorBrush redBrush = new SolidColorBrush(); 
redBrush.Color = Colors.Red; 
SolidColorBrush blackBrush = new SolidColorBrush(); 
blackBrush.Color = Colors.Black; 
redEllipse.StrokeThickness = 4; 
redEllipse.Stroke = blackBrush; 

redEllipse.Fill = redBrush; 

UPDATE : ". 그러나,이 타원에 이미 채우기를 제거"

LinearGradientBrush myBrush=new LinearGradientBrush(); 

myBrush.SetValue(LinearGradientBrush.StartPointProperty, ("0,0")); 
myBrush.GradientStops(1).Offset = 0.5; 

myBrush.SetValue(LinearGradientBrush.EndPointProperty, ("1,1")); 
myBrush.GradientStops(0).Color = Colors.Red; 

myBrush.GradientStops(1).Color = Colors.Green; 

newEllipse.Fill = myBrush; 
+0

Adventure에 감사드립니다. 어쨌든 LinearGradientBrush를 사용해도 되나요? –

+0

알아 냈어! 고마워! :) –

관련 문제