1

Some form of this question seems to have been asked about 1,000 times here, but I am so ignorant of XAML binding that I might as well be reading Greek when I look at the answers. I just don't understand all the datacontexts, itemssources, bindings, displaymemberpaths, etc, and the values that can be assigned to them. Winform binding seems relatively simple.

I'm developing a DB schema along with some algorithms to operate on the DB. I'm not a GUI developer so I just want drop-and-go bare bones functionality that will allow me to edit items within the hierarchy of our database and launch computations on them. I created the data model using EF from a database, and then created data sources from the EF models. I then drag the appropriate tables onto the WPF window and, other than having to change the HashSet types to ObservabileCollections, everything is automatically generated and it seems to work great.

However, one of the columns in a table is a foreign key for which I selected a combobox with the hopes of allowing the user to set that value from values in the parent.

Here's the automatically generated XAML. The parent table of the Plans table is OptimizationSets and I'd like to display the OptimizationSet.Description column in the combobox, but of course select the OptimizationSetId.

<Window.Resources>
  <CollectionViewSource x:Key="userProfileAdvisorsInvestorsPlansViewSource" Source="{Binding Plans, Source={StaticResource userProfileAdvisorsInvestorsViewSource}}"/>
</Windows.Resources>
....
      <DataGrid x:Name="dgPlans" AutoGenerateColumns="False" EnableRowVirtualization="True"
                ItemsSource="{Binding Source={StaticResource userProfileAdvisorsInvestorsPlansViewSource}}"
                RowDetailsVisibilityMode="VisibleWhenSelected">
        <DataGrid.Columns>
          <DataGridTemplateColumn x:Name="optimizationSetIdColumn" Header="Optimization Set Id">
            <DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                <ComboBox>
                  <ComboBoxItem Content="{Binding OptimizationSetId}"/>
                </ComboBox>
              </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
          </DataGridTemplateColumn>
        </DataGrid.Columns>
      </DataGrid>

I know this has been answered, but the answers get me more confused. Surely, there's an easy way to bind the combobox displayed items to the parent.

This is easiest answer I found, but why is the acestortype {x:type window}?

Community
  • 1
  • 1
jlear
  • 160
  • 1
  • 3
  • 14
  • While playing around with intellisense in the ItemsSource property of the ComboBox properties, it looked like the all the columns of the plan where selectible, including the parent table (OptimizationSets). This would make sense to me if it worked, which it doesn't: `` – jlear Nov 10 '16 at 04:19

0 Answers0