ボーダー、2 つのボタン、2 つの jpg ファイルがあります。
これは私の最初のボタンのコードです:
private void Button1_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri(@"C:\Users\abc\Documents\t1.jpg", UriKind.Relative);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = uri;
bi.EndInit();
ImageBrush ib = new ImageBrush(bi)
{
Stretch = Stretch.UniformToFill,
AlignmentX = AlignmentX.Center,
AlignmentY = AlignmentY.Center
};
myBorder.Background = ib;
}
これは私の2番目のボタンのコードです:
private void Button2_Click(object sender, RoutedEventArgs e)
{
File.Copy(@"C:\Users\abc\Documents\t2.jpg", @"C:\Users\abc\Documents\t1.jpg", true);
}
私がやっていること:
- 初期状態:
- ボタン 1 (設定) をクリックします。画像
t1.jpg
は の背景として設定されますmyBorder
。それは大丈夫です。
ボタン 2 (ファイルの変更) をクリックします。
t1.jpg
ファイルの内容がファイルの内容に置き換えられt2.jpg
、名前は変更されません。ボタン 1 (設定) をもう一度クリックします。 file の内容が file の内容に置き換えられ
myBorder
たため、背景が異なるはずです。しかし、何も起こりませんでした!なんで?t1.jpg
t2. jpg