-1
我想创建一个圆形的“播放”按钮。 我想使用2张照片。 1是默认图片,名称为:“PlayButton.png” 另一个应该在用户点击图片文件夹内名为“PlayButtonPressed.png”的按钮后出现。Databind ImageBrush里面的椭圆里面的一个按钮
我试图使用ImageBrush的ImageSource的简单数据绑定来检查它。 但是Inotifychange propery保持为空。并没有图片看起来。不是程序运行时,而是单击空按钮时。
我该如何使用数据绑定来控制图像源。
这里是我的代码:
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#视图模型:
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#常量值
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
没有看到图像 –