帮助!!!我有一个绑定到可观察集合的网格。当且仅当集合中有项目时,我需要将一行显示为第一个项目:
<Grid x:Name="Broadcast" Opacity="0.85" MouseEnter="Broadcast_MouseEnter" Grid.Row="2" Margin="0,0,0,0" Width="Auto" HorizontalAlignment="Right" RenderTransformOrigin="0,0">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Grid.RenderTransform>
<Border
x:Name="broadcastBorder"
Opacity="0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
BorderThickness="3"
BorderBrush="Black"
Background="White"
CornerRadius="5"
RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0" ScaleY="0"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
<ListBox Height="100" ItemsSource="{Binding}" x:Name="icAlerts" Grid.Row="1" >
<!--<TextBlock Text="Clear All" />
<Button Tag="" Content="X" Click="DeleteBroadcast_Click" />-->
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Background="Red" x:Name="spAlerts" Margin="10" Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Template>
<ControlTemplate TargetType="ListBox">
<Border>
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Rectangle Grid.ColumnSpan="2" Stroke="LightGray" StrokeThickness="2"
RadiusX="15" RadiusY="15" Margin="15"
Height="Auto" Width="Auto">
</Rectangle>
<TextBlock Grid.Column="0" Text="{Binding}" />
<Button Grid.Column="1" Tag="{Binding}" Content="X" Click="DeleteBroadcast_Click"></Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
</Grid>
BroadcastMessages = new ObservableCollection<string>();
BroadcastMessages.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(BroadcastMessages_CollectionChanged);
icAlerts.ItemsSource = BroadcastMessages;
如何使第一行看起来像“标题”行?