KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to get a WPF combobox working (inside the WPFToolkit Datagrid), and I'm having trouble getting all the pieces aligned correctly. I'm using Linq to Entities, and I'm setting the overall datacontext to the results of a Linq query: private void LoadDonationGrid() { donationGrid.ItemsSource = from donations in entities.Donation .Include("Family") .Include("PledgeYear") .Include("DonationPurpose") from donationPurposes in entities.DonationPurpose select new { donations, donationPurposes }; } I also have a page property in my code-behind which provides the ItemsSource for the combobox: private IEnumerable donationPurposeList; public IEnumerable DonationPurposeList { get { if (donationPurposeList == null) { donationPurposeList = from dp in entities.DonationPurpose select dp; } return donationPurposeList.ToList(); } } The XAML for the combobox looks like this: <tk:DataGridTemplateColumn Header="Purpose"> <tk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Path=donations.DonationPurpose.Description, Mode=TwoWay}" /> </DataTemplate> </tk:DataGridTemplateColumn.CellTemplate> <tk:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <ComboBox Name="cboDonationPurpose" SelectedValue="{Binding Path=donations.DonationPurposeID, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor},Path=DonationPurposeList}" DisplayMemberPath="Description" SelectedValuePath="DonationPurposeID" />
Tags (comma-separated)
Save Edits
Cancel