1
コードから9つのボタンに背景色と9つの前景画像を追加します。 WPF/xamlではなくC#から画像を変更したいと思います。 背景色を使用して[OK]を動作します:ボタンに画像を挿入する前景
button1.Background.SetValue(SolidColorBrush.ColorProperty, Windows.UI.Colors.Red);
Windowsフォーム使用して簡単な解決策を持っています
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