tags:

views:

203

answers:

2

I have a combobox setup in xaml and have set the itemsource binding. When i run the project nothing shows up in the combobox. If i inspect it with snoop the itemsource of the combobox is blank.

Anyone come across this before?

I checked the binding errors this is the error it displays

System.Windows.Data Error: 39 : BindingExpression path error: 'WasteTypeData' property not found on 'object' ''JobItems' (HashCode=28494546)'. BindingExpression:Path=WasteTypeData; DataItem='JobItems' (HashCode=28494546); target element is 'ComboBox' (Name='CboWasteTypes'); target property is 'ItemsSource' (type 'IEnumerable')

'WasteTypeData' is a public property of ObservableCollection

this is what i have set as the binding of the combobox and if i debug the app 'WasteTypeData' is populated with the list of WasteTypes as expected.

I can't figure out why it's looking for 'WasteTypeData' on object 'JobItems' 'WasteTypeData' property not found on 'object' ''JobItems'

JobItemsData is a public property of ObservableCollection

My xaml has a listbox with its Itemsource Binding set to JobItemsData.

The listbox has a data template with a couple of textboxes and one combobox. All the textboxes display their data properly.

Here's xaml if it will help shed any light on what's going on:

<UserControl
    x:Class="WorkItems.View.ViewJobItems"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:JobItemsViewModel="clr-namespace:WorkItems.ViewModel"
    Height="300" Width="500">
    <ListBox
        x:Name="LstJobItems"
        ItemsSource="{Binding JobItemsData}"
        VerticalAlignment="Stretch"
        HorizontalAlignment="Stretch">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <StackPanel
                        Grid.Column="0"
                        Margin="5">
                        <StackPanel
                            Orientation="Horizontal"
                            Margin="0,5,0,0">
                            <Label
                                Content="Customer Details"
                                FontWeight="Bold"
                                FontSize="24"></Label>
                        </StackPanel>
                        <StackPanel
                            Orientation="Horizontal">
                            <Line
                                StrokeThickness="3"></Line>
                        </StackPanel>
                        <StackPanel
                            Orientation="Horizontal"
                            Margin="0,5,0,0">
                            <Label
                                Content="Customer: "
                                FontWeight="Bold"
                                Width="110" />
                            <TextBox
                                Text="{Binding Customer, Mode=OneWay}"
                                Width="200" />
                        </StackPanel>
                        <StackPanel
                            Orientation="Horizontal"
                            Margin="0,5,0,0">
                            <Label
                                Content="Address: "
                                FontWeight="Bold"
                                Width="110" />
                            <TextBox
                                Text="{Binding Address1, Mode=OneWay}"
                                Width="200" />
                        </StackPanel>

                        <StackPanel
                            Grid.Column="1"
                            Margin="5">
                            <StackPanel
                                Orientation="Horizontal"
                                Margin="0,5,0,0">
                                <Label
                                    Content="Job Details"
                                    FontWeight="Bold"
                                    FontSize="24"></Label>
                            </StackPanel>
                            <StackPanel
                                Orientation="Horizontal">
                                <Line
                                    StrokeThickness="3"></Line>
                            </StackPanel>
                            <StackPanel
                                Orientation="Horizontal"
                                Margin="0,5,0,0">
                                <Label
                                    Content="Date: "
                                    FontWeight="Bold"
                                    Width="110" />
                                <TextBox
                                    Text="{Binding JobDate, Mode=OneWay}"
                                    Width="200" />
                            </StackPanel>
                            <StackPanel
                                Orientation="Horizontal"
                                Margin="0,5,0,0">
                                <Label
                                    Content="Waste Type: "
                                    FontWeight="Bold"
                                    Width="110" />
                                <ComboBox
                                    x:Name="CboWasteTypes"
                                    IsEditable="False"
                                    ItemsSource="{Binding Path=WasteTypeData}"
                                    DisplayMemberPath="WasteType"
                                    SelectedValuePath="WasteTypeID"
                                    SelectedValue="{Binding WasteTypeID}"
                                    Width="200" />
                            </StackPanel>
                            <StackPanel
                                Orientation="Horizontal"
                                Margin="0,5,0,0">
                                <Label
                                    Content="Status: "
                                    FontWeight="Bold"
                                    Width="110" />
                                <TextBox
                                    Text="{Binding Status, Mode=OneWay}"
                                    Width="200" />
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</UserControl>

Thanks Paul

A: 

Check the Output window for any binding errors. You may have misspelled something or not set the DataContext correctly.

qntmfred
A: 

I think its failing because when you use {Binding Path=WasteTypeData} in your combobox, it expects to find it as a property in JobsItems instead of the observable collection, since that is what the parent control (your ListBox) is bound to.

Add WasteTypeData as a static resource in your user control, then bind your combobox to that, specifying it using "{Binding Source={StaticResource..."

<UserControl
   ...
   xmlns:local="WorkItems"
   ...
   Height="300" Width="500">
<UserControl.Resources>
   <local:WasteTypeData x:Key="WasteTypeData"/>
</UserControl.Resources>
..
<ComboBox
   x:Name="CboWasteTypes"
   IsEditable="False"
   ItemsSource="{Binding Source={StaticResource WasteTypeData}}"
   DisplayMemberPath="WasteType"
   SelectedValuePath="WasteTypeID"
   SelectedValue="{Binding WasteTypeID}"
   Width="200" />

See if that helps!

Patrick Pohler
yeah i tried that Patrick but it doesn't seem to be able to see the observable collection 'WasteTypeData' even though it's a public property in the JobItemsViewModel.xmlns:local="clr-namespace:WorkItems.ViewModel">The JobItemsViewModel.cs is in folder called ViewModel.The type 'local:WasteTypeData' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been builtThanksPaul
Paul