I have a separate class PicContainer with a field of type Bitmap. How can I bind this field to the "image" control? PicContainer class code:
class PicContainer : INotifyPropertyChanged { public Bitmap image; public Bitmap Image { get { return image;} set { image = value; } } public String text = "Превет"; public String Text { get { return text;} set { text = value; } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(String propertyName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } Main form:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { PicContainer SimpleClass = new PicContainer(); SimpleClass.Image = new Bitmap("1.jpg"); } } XAML code:
<Window x:Class="imageControl.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:imageControl" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.Resources> </Window.Resources> <Grid> <StackPanel> <Image x:Name="Pic" Margin="5" Source="{Binding ElementName=PicContainer ,Path=SimpleClass.Image}"></Image> <Button x:Name="Button" Content="{Binding Path=Class.Text}" Click="Button_Click" Height="20"></Button> </StackPanel> </Grid> </Window> Result 0. How do I change the XAML markup for the picture to load?
set { image = value; } }set { image = value; } }where do you call OnPropertyChanged () here? - BulsonBitmap? Isn't this a WinformSystem.Drawing.Bitmap? - VladD