UIElement의 Background 속성을 설정하는 일반적인 방법을 찾으려고합니다.UIElement 또는 보낸 사람의 배경 얻기
나는 많은 행운을 가지고 있지 않다 ...
는 여기에 지금까지합니다 (BackgroundProperty를 얻기 위해 반사를 사용하려고 시도) 한 내용입니다.
는Action<UIElement> setTheBrushMethod = (UIElement x) =>
{
var brush = new SolidColorBrush(Colors.Yellow);
var whatever = x.GetType().GetField("BackgroundProperty");
var val = whatever.GetValue(null);
((UIElement)x).SetValue(val as DependencyProperty, brush);
brush.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation(Colors.White, TimeSpan.FromSeconds(3)));
};
setTheBrushMethod(sender as UIElement);
것은 그것이 TextBlock이 같은 뭔가를 작동하지만 StackPanel의 또는 버튼과 같은 작동하지 않습니다 ...입니다.
"무엇이든"은 StackPanel 또는 Button에 대해 null이됩니다.
배경을 일반적으로 설정하는 쉬운 방법이 있어야한다고 생각합니다. 나는 분명히 분실 했습니까?
Background는 System.Windows.Controls.Control에서만 사용할 수있는 것으로 보입니다.하지만 그걸 캐스팅 할 수 없습니다. 여기
이 var whatever
해야한다 무엇 아니라 BackgroundProperty
DependencyProperty에 당신이 Background
재산를 찾고 있습니다 :
음 ... 스타일을 사용 해본 적이 있습니까? – failedprogramming