0

我正在创建一个带有使用网格的 ItemContainer 的自定义 ListBox。目标是将每个项目添加到特定的列、行,并具有特定的行跨度。这些数字在 ObservableCollection ScheduledCourses 中设置为可绑定属性。在 DataTemplate 上,我能够指定 DataType,然后能够从集合中进行绑定。但我无法在 Style 上指定 DataType。如何设置 BlockPlacement 中的值以绑定所需的属性?

PS。我正在使用 MVVM Light。

<UserControl.Resources>
    <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
    <CollectionViewSource x:Key="CoursesByDay" Source="{Binding ScheduledCourses}">
        <CollectionViewSource.GroupDescriptions>
            <PropertyGroupDescription PropertyName="MeetsOn" />
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

    <DataTemplate x:Key="ScheduleBlock" DataType="vm:ScheduleBlockViewModel">
        <userControls:ScheduleBlock />
    </DataTemplate>

    <ItemsPanelTemplate x:Key="ScheduleDayGrid">
        <!--  Replace with Schedule Day Grid  -->
        <Grid Name="ScheduleDayGrid"
              Width="400"
              Initialized="ScheduleDayGridInitialized"
              ShowGridLines="True" />
    </ItemsPanelTemplate>

    <Style x:Key="BlockPlacement" TargetType="ListBoxItem">
        <Setter Property="Grid.Column" Value="{Binding Path=ScheduledCourses[].TimeSlotIndex}" />
        <Setter Property="Grid.Row" Value="{Binding ScheduledCourses[].StartTimeIndex}" />
        <Setter Property="Grid.RowSpan" Value="{Binding ScheduledCourses[].DurationIndex}" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="Grid.VerticalAlignment" Value="Stretch" />
    </Style>
</UserControl.Resources>
<UserControl.DataContext>
    <Binding Mode="OneWay"
             Path="ScheduleGrid"
             Source="{StaticResource Locator}" />
</UserControl.DataContext>
4

0 回答 0