1
votes

Edit: Rewritting question

I use the Project Management Library from http://dlhsoft.com/Home.aspx in my WPF usercontrol.

I'm displaying their LoadChartResourceListView control on my page and use a datatemplate to display custom columns in a list view:

<my:LoadChartResourceListView TaskManagerSource="{Binding ElementName=ganttChartTaskListView,Path=TaskManager}" 
                                TimelinePageStart="{Binding TimelinePageStart, ElementName=ganttChartTaskListView, Mode=TwoWay}"
                                TimelinePageFinish="{Binding TimelinePageFinish, ElementName=ganttChartTaskListView, Mode=TwoWay}" 
                                DisplayedTime="{Binding DisplayedTime, ElementName=ganttChartTaskListView, Mode=TwoWay}"
                                Margin="6" Name="loadChartResourceListView">
        <my:LoadChartResourceListView.View>
            <GridView ColumnHeaderContainerStyle="{StaticResource ListViewColumnHeaderContainerStyle}">
                <!-- Set CellTemplate (or CellTemplateSelector) to specify column templates. -->
                <GridViewColumn Header="Group" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Width="85" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, 
                                AncestorType={x:Type inf:MEFUserControl}}, Path=DataContext.ResourceGroups}" 
                                DisplayMemberPath="GroupName"
                                SelectedValuePath="GroupID" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>  
                <GridViewColumn Header="Resource">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox x:Name="myTB" Text="{Binding Content}"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

The whole user control (inf:MEFUserControl) that contains this LoadChartResourceListView has a datacontext set to an instance of my viewmodel class (TaskData). Within the TaskData class is a ObservableCollection<ResourceGroup> ResourceGroups {get;set;}. Each ResourceGroup has an int GroupID {get;set;} and string GroupName{get;set;}.

Also, within the TaskData class is an ObservableCollection<Resource> Resources {get;set;} ... each Resource has a int GroupID{get;set;}, string Content {get;set;} and ResourceGroup ResGroup{get;set;}

The above code works fine with displaying the combobox and the textbox... I cannot, for the life of me, figure out why I'm having issues binding to the SelectedValue property of the combobox. I've many things including SelectedValue="{Binding GroupID}"

Everytime I try to set the SelectedValue I receive this error popup in VS: "A first chance exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll" This is the error from the output window (its massive) http://pastebin.com/AGJwn00C

From reading, I've read that this is due to a parent object having a property with the same name "GroupID". I've renamed GroupID to ResGroupID in the Resource class, thinking that it conflicted with the ResourceGroup class, but I receive the same error.

When I set this ItemsSource, is the DataContext for the combobox being set to the UserControl or TaskData instance?

Update:

I receive the error also when I use a TextBox instead of a combobox:

<TextBox Text="{Binding GroupID}"/>
2
Where are the Selected value coming from? You have set the binding to a GroupID property of LoadChartResourceListView,Which does not exists i think.You can go the Output window and the binding error should be logged there.biju
SelectedValue is from each element in my ObservableCollection<Resource> ... each element is enumerated through this LoadChartResourceListView.View and displayed on the screen. Honestly... it probably has nothing to do with LoadChartResourceListView... I just need to know how to get a binding to the same object that the following data template is bound to - since the datacontext appears to have changed whedn setting my combobox's itemssource... I added 2 new paragraphs to the end of the questionChris Klepeis

2 Answers

0
votes

Just write

SelectedValue="{Binding Path=GroupID}"

0
votes

Solved it. After reading this: http://dlhsoft.com/KnowledgeBase/Task-Appearance-Bar-Templating-Custom-Data-Binding.htm

I had to do Item.PropertyName for custom properties.