In WPF, each control has its own default template (what it looks like), but you can easily change these templates and make the controls look the way you want. This facilitates the choice of control for its functionality and makes it look like what you want. In your case, you want Click to select a Button and change its Template
<Window ...> <Window.Resources> <Style TargetType="{x:Type Button}" x:Key="ImageButtonStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <ContentPresenter/> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Button Style="{StaticResource ImageButtonStyle}" Click="ImageButton_Click"> <Image Source="..."/> </Button> </Window>
With the above XAML Image will be your Button
EDIT
Below you can find a simplified version of how to bind / modify Image.Source , where everything is done in MainWindow, but basically in WPF you do not control the controls, but bind their properties using Binding and manage these properties. Usually you will create a dedicated class (ViewModel). Your class needs to implement the INofityPropertyChanged interface, the DataContext must be set appropriately, and the related property should raise the INofityPropertyChanged.PropertyChanged event every time its value changes (that you notify the user interface to update the value)
public partial class MainWindow : Window, INotifyPropertyChanged { public MainWindow() { InitializeComponent(); DataContext = this; } private ImageSource _myImageSource; public ImageSource MyImageSource { get { return _myImageSource; } set { _myImageSource = value; OnPropertyChanged("MyImageSource"); } } private void ImageButton_Click(object sender, RoutedEventArgs e) { this.MyImageSource = new BitmapImage(...);
and in XAML:
<Button Style="{StaticResource ImageButtonStyle}" Click="ImageButton_Click" Width="..." Height="..."> <Image Source="{Binding MyImageSource}"/> </Button>
dkozl source share