I am trying to do a small thing with DataBinding in WPF and C#, but I can't understand any of the tutorials for DataBinding.. my problem is, that I have a character class in C# and it has X and Y Coordinates with get and set functions. Then I have an image in a canvas in the window and now I am trying to bind the coordinates from the character class to the image. (There is only one image, and there will be created only one instance of the character class, though not at the beginning). Hope anyone can explain it so that I can fully understand it :/
EDIT:
Here is the XAML:
<Window x:Class="ProjectChar.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="1000" Background="Gray">
<Viewbox StretchDirection="Both" Stretch="Uniform">
<Grid>
<Canvas Name="Canv" Background="White" Visibility="Hidden" MaxHeight="750" MaxWidth="1000">
<Canvas.LayoutTransform>
<ScaleTransform ScaleY="-1"/>
</Canvas.LayoutTransform>
<Image Name="CharImage" Source="CharBild.png" Canvas.Left="{Binding iXCoordinate}" Canvas.Top="{Binding iYCoordinate}"/>
</Canvas>
</Grid>
</Viewbox>
and here is the C#-Part:
namespace ProjectChar
{
public class Char : MainWindow
{
public int iXCoordinate { get; set; }
public int iYCoordinate { get; set; }
}
}
So I somehow need to bind them together, but I don't exactly know how. I know that I have to create a DataContext and that I need to set the UpdateSource to PropertyChanged and that I need an EventHandler for the Property Changed, but I don't know how to do any of that and the tutorials on the internet are all saying kind of different things :/