1
코드에서 9 개의 버튼에 배경색과 9 개의 전경 이미지를 추가하고 싶습니다. WPF/xaml이 아닌 C#에서 이미지를 변경하고 싶습니다.Button Foreground에 이미지 삽입
button1.Background.SetValue(SolidColorBrush.ColorProperty, Windows.UI.Colors.Red);
윈도우 양식을하고있다 사용하기 쉬운 솔루션을 :
pictureBox1.Image = Properties.Resources.P1; // this does not work for UWP
내가 지금까지 시도 오류 메시지가 끝나는 것을 : 를 내가 빌드 작업 속성을 변경 한 배경 색상 사용하여 작동 확인 P1.png를 PRIResource로 복사하십시오.
string url = "../../Images/P1.png";
//string url = "PW.png";
image1.Source = new BitmapImage(new Uri(url, UriKind.Relative)); //.Uri cannot be converted into a Windows.Foundation.Uri.
//image1.Source = new BitmapImage(new Uri(url, UriKind.Absolute)); //format of url could not be determined
<Button x:Name="button1" Content="Button" Grid.Column="0" Grid.Row="0"
Tag="1" Background="Gray" Padding="0" UseLayoutRounding="False"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Click="button1_Click">
<Button.Foreground>
<ImageBrush Stretch="Fill" ImageSource="P1.PNG"/>
</Button.Foreground>
</Button>
xaml에서 수행하는 것과 동일한 코드를 수행하려고 시도 했습니까? - 새로운 ImageBrush()를 만들고, * ImageSource *를 설정 한 다음, 버튼에 연결합니까? – Romasz
[전경 및 배경이 이미지 인 [wpf 버튼]의 가능한 복제본] (http://stackoverflow.com/questions/4107813/wpf-button-with-foreground-and-background-as-image) –
안녕하세요 Romasz. ImageSource를 설정하고 단추를 부착하는 방법에 대한 샘플 코드를 가르쳐 주시겠습니까? 감사합니다 – GolfCalcs