I have the following classes
ImageViewModel: INotifyPropertyChanged
{ ...
String Url;
}
AdViewModel: INotifyPropertyChanged
{ ...
ImageViewModel Image
}
The AdViewModel perodicaly changes the Image property (animated Ad).
When I have the following XAML:
<Grid>
<Image Source="{Binding Image.Url}"
Width="{Binding Image.Width}"
Height="{Binding Image.Height}" />
And set the Grids DataContext to an instance of AdViewModel everything works as expected. But I need to create the XAML in C# code to use it elsewhere. Creating a Grid and appending an Image as its child is easy, but how to a create the bindings?
I found an easier way. I created the XAML as a UserControl, saved it in a file (Templates\SkyScrapper.xaml). Then instead of creating the controls in C# a just load the XAML File
and set its DataContext
There is now no need to create the bindings in C#, they are defined in the XAML file.