I have a usercontrol I have created. It is used within the DataTemplate of a list box.
The listbox is bound to an observable collection of custom objects.
I need a way to pass the current object to my usercontrol via binding.
I have tried to create a public property on the user control as such:
public TypedMediaItem CurrentItem { get; set; }
And set the binding parameters:
<my:LargeStreamItemControl Height="160" Width="295" CurrentItem="{Binding }" />
However this gives me the following error:
Object of type ‘System.Windows.Data.Binding’ cannot be converted to type ‘F1MediaCentre.Classes.Payload.Typed.TypedMediaItem’.
I am unsure where I am going wrong – I am new to Silverlight, having inherited a live production application from a former colleague, and am racking my brains with this one.
I’ll take a stab at this… it is possible that you can’t bind to it because it is not a dependency property.
Add this to your user control in place of your current CurrentItem:
Sorry I do mostly VB… hope you can convert to C# 🙂
This will make it a dependency property and therefore you’ll be able to bind to it.
Okay, here’s C#: