0

So, I am using an ItemsControl in order to iterate through a Bindable collection of some Notification objects, which are essentially just records. They and their related class all are derived from my class NotificationBase. It seems that I am able to bind the collection to the items control (though I wasn't able to use Caliburn to do it since I haven't written a converter for it.) But I keep getting nulls and blank spots because of path not found errors: BindingExpression path error: 'base' property not found on 'object' ''DebugNotification', because it's not explicitly defined since it's inherited from the base class.

Here is the declaration of the containers.

<StackPanel Name="NotificationsList" Grid.Row="1" ScrollViewer.CanContentScroll="True">
        <ItemsControl ItemsSource="Notifications">

In each iteration there will be a textblock like this for the template.

<TextBlock Name="Title" HorizontalAlignment="Stretch" VerticalAlignment="Top" Text="{Binding base.title}">
                                </TextBlock>

Is there any way for me to access that ancestral data from the xaml, or do I have to explicitly define those getters for each of the derived classes? Perhaps there's a better solution in Caliburn?.Micro?

If anyone needs more context, here is the whole body of code for the panel which I omitted for clunkiness:

    <StackPanel Name="NotificationsList" Grid.Row="1" ScrollViewer.CanContentScroll="True">
        <ItemsControl ItemsSource="Notifications">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Label Name="NotificationMessageTemplate" Style ="{DynamicResource NotificationEntry}">
                        <Grid HorizontalAlignment="Stretch" Width="{Binding ElementName=NotificationMessageTemplate, Path=ActualWidth}" Height="{Binding ElementName=NotificationMessageTemplate, Path=ActualHeight}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                                <RowDefinition Height="*"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" VerticalAlignment="Stretch">
                                <TextBlock Name="Title" HorizontalAlignment="Stretch" VerticalAlignment="Top" Text="{Binding base.title}">
                                </TextBlock>
                            </Label>
                            <Label Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" VerticalAlignment="Stretch">
                                <TextBlock Name="Message" HorizontalAlignment="Stretch" VerticalAlignment="Top" Text="{Binding base.message}">
                                </TextBlock>
                            </Label>
                        </Grid>
                    </Label>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>
3
  • For one you might be bouncing off the convention to bind to a name of the property or base property in the class object. I would suggest dropping names off the TextBlocks that don't require being named, since you are doing binding, choose which you want to do binding or convention don't do both. Second in Notifications is there a property named Message? or Title? I am assuming there is and it is probably inherited?
    – mvermef
    Nov 20, 2014 at 3:15
  • basically the error is saying we can't find a property in your collection of Notifications called 'base'. Also the binding for ItemsSource is alittle off... <ItemsControl ItemsSource="{Binding Notifications}" />.
    – mvermef
    Nov 20, 2014 at 3:23
  • Ah okay. I will try that and update you. But yes, Notifications has properties message and title. And it looks like I forgot to edit it to the way it was before where it was just Binding Path=title. The base.title was just there for me to experiment on where that would work. But yeah, the problem is that the methods from the base classes are hidden and need to explicitly have getters defined for them in order for XAML to see title and message, instead of the implicitly being there as part of the inheritance. Nov 20, 2014 at 8:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.