Caliburn.Micro / WPF:绑定和访问基类数据

时间:2014-11-20 00:31:25

标签: c# wpf xaml caliburn.micro

所以,我使用ItemsControl来迭代一些Notification对象的Bindable集合,这些对象基本上只是记录。它们及其相关类都来自我的NotificationBase类。似乎我能够将集合绑定到items控件(虽然我没有使用Caliburn来执行它,因为我没有为它编写转换器。) 但是由于路径未找到错误,我一直得到空值和空白点:BindingExpression path error: 'base' property not found on 'object' ''DebugNotification',因为它没有明确定义,因为它是从基类继承的。

这是容器的声明。

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

在每次迭代中,模板都会有这样的文本块。

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

我有什么方法可以从xaml访问祖先数据,还是我必须为每个派生类显式定义这些getter?也许在Caliburn有更好的解决方案?.Micro?

如果有人需要更多上下文,这里是面板的全部代码,我为了笨拙而省略了:

    <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>

0 个答案:

没有答案