문제

how can I programmatically set the background of a button to be an image? I know how to do it in XAML, but in code, I keep getting stuck, I tried

Button.Background = new ImageBrush{ ImageSource = "source" };

but then I get the error that string cannot be converted to ImageSource.

도움이 되었습니까?

해결책

Try:
Button.Background = new ImageBrush{ ImageSource = new BitmapImage(new Uri(imgPath, UriKind.Relative)) };
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top