0

次のコードを使用して、WPFのネストされたStackPanelにデータをバインドしようとしています-無駄です。誰かが私が間違っているところを見つけることができますか?

    <Page.Resources>
    <DataTemplate x:Key="MinuteTimeSlotTemplate">
        <TextBlock Text="{Binding Path=TourName}" Background="Blue" />
    </DataTemplate>
    <DataTemplate x:Key="HourlyTimeSlotTemplate">
        <StackPanel>
            <Border Height="120" BorderThickness="0,0,0,1" BorderBrush="#DDD" x:Name="parentRow">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="123"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="0,0,10,0" MouseUp="StackPanel_MouseUp_1">
                        <TextBlock Foreground="#4585B9" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="20" HorizontalAlignment="Right">
                            <Run Text="{Binding Path=Time}"/></TextBlock>
                        <TextBlock FontFamily="Trebuchet MS" Foreground="#808080" HorizontalAlignment="Right"><Run Text="View Bookings"/></TextBlock>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Grid.Column="1" Margin="10,0,10,0" x:Name="stk">
                        <ItemsControl ItemTemplate="{StaticResource MinuteTimeSlotTemplate}" ItemsSource="{Binding Path=HourlySlots}" >
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel Orientation="Vertical"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                        </ItemsControl>
                    </StackPanel>
                </Grid>
            </Border>
        </StackPanel>
    </DataTemplate>
</Page.Resources>
<helpers:AnimatedScrollViewer  x:Name="scrlHours" Grid.Column="1" PanningMode="Both" PanningDeceleration="5" PanningRatio="2">
    <ItemsControl x:Name="TimeSlotList" ItemTemplate="{StaticResource HourlyTimeSlotTemplate}" >
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
</helpers:AnimatedScrollViewer>

親のStackPanelsItemsSourceをコードで設定しました。

public HourlyCalendar() {
        InitializeComponent();
        TimeSlotList.ItemsSource = new Models.TimeSlots(DateTime.Today).HourlySlots;
    }

そして、これが私のモデルです:

    public class TimeSlots {

    public TimeSlots(DateTime? day) {
        this.HourlySlots = DataManager.GetCalendarDayTimeSlots(day);
    }

    public IEnumerable<TimeSlot> HourlySlots { get; set; }

}

親のStackPanelは期待どおりにバインドされますが、子のStackPanelをバインドする方法がわかりません...

4

1 に答える 1

1

それはかなり単純であることがわかりました:

    <helpers:AnimatedScrollViewer x:Name="scrlHours" Grid.Column="1" PanningMode="Both" PanningDeceleration="5" PanningRatio="2">
    <ItemsControl x:Name="TimeSlots">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
               <Border Height="120" BorderThickness="0,0,0,1" BorderBrush="#DDD" x:Name="parentRow">
                    <StackPanel Orientation="Horizontal">
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="0,0,10,0" Width="123" MouseUp="StackPanel_MouseUp_1"> <!--Height="{Binding Height, ElementName=parentRow}"-->
                            <TextBlock Foreground="#4585B9" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="20" HorizontalAlignment="Right">
                            <Run Text="{Binding Path=Time}"/></TextBlock>
                            <TextBlock FontFamily="Trebuchet MS" Foreground="#808080" HorizontalAlignment="Right"><Run Text="View Bookings"/></TextBlock>
                        </StackPanel>
                        <ListView ItemsSource="{Binding Bookings}" ScrollViewer.CanContentScroll="False">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding TourName}"></TextBlock>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListView>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</helpers:AnimatedScrollViewer>
于 2012-12-16T17:19:16.500 に答える