Ich möchte einen Kreis "Play" -Taste erstellen. Ich möchte 2 Fotos verwenden. 1 ist das Standard-Bild namens "PlayButton.png" und ein anderes, das erscheinen sollte, nachdem der Benutzer auf den Button namens "PlayButtonPressed.png" geklickt hat.Die Quelle von ImageBrush innerhalb elipse innerhalb einer Taste
Ich habe versucht, eine einfache Datenbindung für die ImageSource des ImageBrush zu verwenden, um dies zu überprüfen. Die Inotifychange-Eigenschaft bleibt jedoch null. und keine Bilder werden angeschaut. nicht wenn das Programm läuft und nicht wenn man auf die leere Schaltfläche klickt.
Wie kann ich das mit Datenbindung zur Kontrolle der Image Source tun.
hier ist mein Code:
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# Ansichtsmodell:
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# Konst Wert
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";
}
Schweller mit der gleichen Ausgabe :( –
Sie sehen nicht die Bild überhaupt? – mm8
Nr. Sehen Sie das Bild überhaupt nicht –