我正在尝试找到一种编码分组用户列表的方法,并能够动态显示分配给他们的工作。我有一个Observable Collection(UsersOC)绑定到我的XAML中的CollectionViewSource(在用户控件的参考资料部分中定义),如下所示:
<CollectionViewSource x:Key="UserQueueList" Source="{Binding QueueList}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Name"></PropertyGroupDescription>
</CollectionViewSource.GroupDescriptions>
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Name"/>
<scm:SortDescription PropertyName="EmployeeNumber"/>
<scm:SortDescription PropertyName="SortOrder"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
所以我拥有的是所有用户及其相关工作的清单。
我必须在列表中(按用户名分组)代表每个驱动程序,无论是否有工作,然后是他们的工作。如果他们没有工作,我需要展示一个&#34;在这里工作&#34;这是一个Drop区域,它将工作添加到队列中。我必须让控件成为驱动程序名称下的ListBox,所以它看起来像这样:
--> Driver Name1
- work 1
- work 2
--> Driver Name2
Drop Work Here
--> Driver Name3
- work 1
- work 2
- work 3
再次列出具有工作项的区域是/应该是列表框,可以单独拖放(我已经拥有该部分代码)。以下是我到目前为止的情况:
<ItemsControl ItemsSource="{Binding Source={StaticResource TrailerCardQueueList}}" Grid.ColumnSpan="2" Grid.Row="1" BorderBrush="Transparent"
Background="Transparent" Name="lvDriverQueueWork" Margin="10,0,10,0" Foreground="Black">
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontSize="14" FontWeight="SemiBold">
<Run Text="{Binding Path=Items[0].EmployeeNumber}"/>
<Run Text="-"/>
<Run Text="{Binding Name, Mode=OneWay}"/>
</TextBlock>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ItemsControl.GroupStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
//I figured I could hide/show the area here with the default drop zone if they have no work, but this doesn't work.
<DataTrigger Binding="{Binding Path=HasItems, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Value="False">
<Setter Property="Visibility" Value="Hidden"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<TextBlock Grid.Row="0" Grid.Column="0" Text="DROP TRAILER CARD HERE"/>
</Grid>
<Grid>
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding HasItems, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<TextBlock Grid.Column="1" Text="{Binding , UpdateSourceTrigger=PropertyChanged}"/>
<TextBlock Grid.Column="2" Text="{Binding , UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>