Motivated Motivated - 22 days ago 10
C# Question

Bind to property of object

I am currently developing a little musicplayer just for fun.
I was wondering if I can bind to a class named Track and access its propertys in XAML.

public class Track
{
public string TitleName { get; set; }
public BitmapImage Cover { get; set; }
}


Code can explain better than I can so here's my pseudo code:

<Grid>
<Image Source="{Binding BindingName="CurrentTrack" PropertyName="Cover"}"/>
<TextBlock Text="{Binding BindingName="CurrentTrack" PropertyName="Title"}"/>
</Grid>


Can I get something like this without using a Converter or sth like that ?

Answer

You can access a child property like this:

<TextBox Text="{Binding CurrentTrack.TitleName}"/>

You must have bound your View to your ViewModel

Comments