I have an object in my business layer (let's call it Car for example's sake), and I have created a UserControl (CarIcon). The user control has a property that is a Car object and when the Car object is set it calls a method that configures the various properties of the user control.
Now I am rewriting it to use dependency properties so that I can use data templates and bind the backing Car object to the CarIcon user control at run time. Ideally, I want to bind the object to the user control and have the user control automatically update it's display.
It seems like the dependency property is not being set and the app is display blank icons (because without the backing object there is no data to display). Am I binding things incorrectly?
Also Is this a reasonable approach (considering I don't want to implement a full MVVM for a simple control)?
Binding the Car to the CarIcon in xaml
<ItemsControl Name="m_itemsControl" Focusable="false"
pixellabs:AnimatingTilePanel.ItemHeight="100" pixellabs:AnimatingTilePanel.ItemWidth="300">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<pixellabs:AnimatingTilePanel Width="300" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<sample:CarIcon CurrentCar="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Code for the dependency property
public Car CurrentCar {
get { return (Car)GetValue( CarProperty ); }
set { SetValue( CarProperty, value ); }
}
public static readonly DependencyProperty CarProperty =
DependencyProperty.Register(
"CurrentCar",
typeof( Car ),
typeof( CarIcon ),
new UIPropertyMetadata() );