Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do you bind to a property on a reference object?
Message
From
17/07/2008 16:04:45
 
 
To
17/07/2008 15:41:24
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01331472
Message ID:
01332081
Views:
7
>Well...The first problem I had was setting the ItemsSource in XAML. I couldn't figure it out, so I do it in the form constrctor. Seeing more of your code, I think I see a slightly diffferent structure...

That does work fine.

>>As far as my ComboBox goes, it is not in a UserControl, it's just a plain UI control in a HeaderedContentControl (I wonder where I learned about that), that is also in a StackPanel, that is also in a Grid. I tried to set ItemsSource="{Binding Path=custs, ElementName=______ (don't know what to put here).

My UserControl was basically the same as your Window, it was the root element of the XAML file.

>So, in code-behind, I set the DataContext of gridMain to a Job, and I also set the ItemsSource on the ComboBox to the full list of Customer objects (the "custs" collection). I really want to figure out setting the ItemsSource in XAML, but haven't so far.

You can't bind to fields so make this a Property:
public IQueryable<Customer> custs { get; set;}
Substitute Window for UserControl:
<Window ... Name="winJobEdit"> ...
Note the element name being used in the binding here:
ItemsSource="{Binding Path=custs, ElementName=winJobEdit}"
>However, that is not really the issue with the greater goal here of updating the Customer reference in a Job from the XAML binding, so I've just been letting the ItemsSource thing slide for now. But I'm certainly curious to figure it out.

Try the code above.

>Also, is your DataStores a collection of strings? I notice you are not having to use DisplayMemberValue and SelectedItemPath. My ItemsSource is a collection of Customer objects, so I have to specify which field on the Customer object is what part. I see that you are using SelectedValue but not the other two.

Datastores is a collection of objects. I'm using a DataTemplate instead, but I think either way should work.
<ComboBox.ItemTemplate>
  <DataTemplate>
    <TextBlock Text="{Binding Path=company}"/>
  </DataTemplate>
</ComboBox.ItemTemplate>
>So you are able to point the ItemsSource to a Path on your UserControl, but what do I need to point to in order to get at the public custs collection?

See above, you can't bind to a field so you have to make it a property.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform