円の「再生」ボタンを作成したいと思います。 2枚の写真を使いたいです。 1は、「PlayButton.png」 と呼ばれるデフォルトの画像で、ユーザーがImagesフォルダ内の "PlayButtonPressed.png"というボタンをクリックした後に表示されるはずです。ボタンの内側にあるImageBrush内のelipse内部のデータバインド
ImageBrushのImageSourceにこれをチェックするための簡単なデータバインディングを使用しようとしました。 しかし、Inotifychangeプロパティはnullのままです。写真は見られません。プログラムが実行されたときではなく、空のボタンをクリックしたときではありません。
Image Sourceを制御するためのデータバインディングを行うにはどうすればよいですか。ここ
は私のコードです:
XAML:
<Window x:Class="COMSimulator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Converters="clr-namespace:COMSimulator"
<Button x:Name="btnStart" Grid.Column="0" Grid.Row="2"
HorizontalAlignment="Center" VerticalAlignment="Center" Width="50"
Height="50" Click="btnStart_Click">
<Button.Template>
<ControlTemplate>
<Ellipse Height="50" Width="50">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding Path=ImagePlayButton}"></ImageBrush>
</Ellipse.Fill>
</Ellipse>
</ControlTemplate>
</Button.Template>
</Button>
</Window >
のC#:
namespace COMSimulator
{
public partial class MainWindow : Window
{
public viewModeImage VMI { get; set; }
public MainWindow()
{
InitializeComponent(); //init componenets
VMI = new viewModeImage();
DataContext = this;
VMI.ImagePlayButton = Consts.IMAGE_PLAY_BUTTON;
}
}
}
C#のViewModel:
namespace COMSimulator
{
public class viewModeImage:INotifyPropertyChanged
{
private string _imagePlayButton;
/// <summary>
/// this method init all window Items to relavent Data
/// </summary>
public string ImagePlayButton
{
get
{
return _imagePlayButton;
}
set
{
_imagePlayButton = value;
OnProperyChanged("ImagePlayButton");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnProperyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
C#のConst値
public static class Consts
{
public const string IMAGE_PLAY_BUTTON [email protected]"Images\PlayButton.png";
public const string IMAGE_PLAY_BUTTON_PRESSED = @"Images\PlayButtonPressed.png";
}
を:( –
あなたが表示されません画像すべてで – mm8
番号画像がまったく表示されない –