3

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 ?

1 Answer 1

3

You can access a child property like this:

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

You must have bound your View to your ViewModel

Sign up to request clarification or add additional context in comments.

5 Comments

I try it out :D give me a sec
Is your View bound to your ViewModel? Is the DataContext set?
My DataContext is set. Is the line you posted the only thing I need ? All other bindings work fine but the ones on the childproperties wont
I didn't call OnPropertyChanged -.- My bad ^^ thx for your help and the fast reply ^^
That was going to be my next suggestion ;) - Glad you figured it out!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.