2014-07-10 2 views
0

문제가 있습니다.mainWindow에서 linearGradientBrush 메서드를 호출하는 방법은 무엇입니까?

내가 LinearGradientBrush에 XAML에서 내 방법 (MainWindow를)를 호출하고 싶은

- 그래서 내가 애니메이션 배경의 색상을 변경하려면>GradientStop

. 코드 XAML에서

public static List<Color> GetGradientColors(Color start, Color end, int steps) 
{ 
    return GetGradientColors(start, end, steps, 0, steps - 1); 
} 

public static List<Color> GetGradientColors(Color start, Color end, int steps, int firstStep, int lastStep) 
{ 
    var colorList = new List<Color>(); 
    if (steps <= 0 || firstStep < 0 || lastStep > steps - 1) 
     return colorList; 

    double aStep = (end.A - start.A)/steps; 
    double rStep = (end.R - start.R)/steps; 
    double gStep = (end.G - start.G)/steps; 
    double bStep = (end.B - start.B)/steps; 

    for (int i = firstStep; i < lastStep; i++) 
    { 
     byte a = (byte)(start.A + (int)(aStep * i)); 
     byte r = (byte)(start.R + (int)(rStep * i)); 
     byte g = (byte)(start.G + (int)(gStep * i)); 
     byte b = (byte)(start.B + (int)(bStep * i)); 
     colorList.Add(Color.FromArgb(a, r, g, b)); 
    } 

    return colorList; 
} 

:

<LinearGradientBrush StartPoint="0.0, 0.6" EndPoint="1.0, 0.6"> 
    <GradientStop Color="{ Binding GetGradientColors(green, yellow, 2)}" Offset="0"/> 
</LinearGradientBrush> 

는이 작업을 수행하는 것이 가능 I은 여러 매개 변수가있는 기능이?

+0

왜 그렇게하려고? 그라디언트 브러시는 자체적으로 보간하기 만하면 '녹색'에 대해 한 번 정지하고 '황색'에 대해 하나씩 중지해야합니다. –

답변

0

첫 번째 유형 ObservableCollection<Color>의 속성을 선언는 Colours 이름을 말할 수 :

public ObservableCollection<Color> Colours { get; set; } 

이 그런 다음 생성자에서 속성을 설정 : XAML에서 그것에

Colours = GetGradientColors(Colors.Green, Colors.Yellow, 2); 

그런 다음 데이터 바인딩 :

정확히 원하는 것은 아니지만 얻을 수있는만큼 가깝습니다.

0

in the binding으로 사용할 수있는 converter을 구현하고 필요한 모든 인수를 Binding.ConverterParameter으로 전달할 수 있습니다. 또한

, 이것은 어쨌든 "바인딩", 당신은 생성자 매개 변수로 인수를 취하는 markup extension을 구현할 수있다 필요로하지 않는 :

<GradientStop Color="{me:GradientColor Green, Yellow, 2}" Offset="0"/> 
+0

제발 GradientStop에서 GetGradientColors() 함수를 호출하는 방법을 알려주시겠습니까? 나는 이것을 부를 수 없다. 답장을 보내 주셔서 감사합니다. – DeveloperTech2013

+0

@ DeveloperTech2013 : 각 메소드에 링크 된 설명서를 읽고 필요한 모든 정보가 포함되어 있어야합니다. –

관련 문제