我似乎无法找到一种方法来实现水木清华很简单:
我有一个ItemsControl
一个UniformGrid
它的内部,即通过安排项目DataTemplate
:
<ItemsControl ItemTemplate="{StaticResource ResourceKey=tmMapCell}"
MouseUp="wpSubMap_MouseUp" BorderThickness="1" BorderBrush="DarkGray">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="8" Rows="6" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
这里的电池模板:
<DataTemplate x:Key="tmMapCell">
<Border BorderBrush="DimGray" BorderThickness="1" Margin="1" Background="Gainsboro" Visibility="{Binding Path=vMapCell}" >
<StackPanel VerticalAlignment="Center">
<TextBlock Margin="2,4,2,2" TextAlignment="Center" Text="{Binding Path=sCell0}" FontWeight="Bold" />
<StackPanel>
<StackPanel.Background><SolidColorBrush Color="{Binding Path=cColorB}" /></StackPanel.Background>
<TextBlock Margin="2,1,2,0" TextAlignment="Center" Text="{Binding Path=sCell1}" FontWeight="{Binding Path=fntWt}">
<TextBlock.Foreground><SolidColorBrush Color="{Binding Path=cColorF}" /></TextBlock.Foreground>
</TextBlock>
<TextBlock Margin="2,1,2,0" TextAlignment="Center" Text="{Binding Path=sCell2}" FontWeight="{Binding Path=fntWt}">
<TextBlock.Foreground><SolidColorBrush Color="{Binding Path=cColorF}" /></TextBlock.Foreground>
</TextBlock>
</StackPanel>
<TextBlock Margin="2" TextAlignment="Center" FontWeight="Normal" Text="{Binding Path=tElapsed, StringFormat='HH:mm:ss'}"></TextBlock>
<StackPanel Margin="0" *MouseUp*="Svc_MouseUp" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Background="White" Visibility="{Binding Path=vSvcs}">
<Border BorderBrush="DimGray" BorderThickness="1" Margin="2,2,0,2">
<StackPanel Name="spSvcGrn" *MouseUp*="Svc_MouseUp">
<TextBlock Name="txSvcGrn" Height="14" Width="16" TextAlignment="Center" FontWeight="Normal" Text="{Binding Path=sSvc1}" Background="Lime" Visibility="{Binding Path=vSvc1}" />
</StackPanel>
</Border>
<Border BorderBrush="DimGray" BorderThickness="1" Margin="2,2,0,2">
<StackPanel Name="spSvcOra" *MouseUp*="Svc_MouseUp">
<TextBlock Name="txSvcOra" Height="14" Width="16" TextAlignment="Center" FontWeight="Normal" Text="{Binding Path=sSvc2}" Background="Orange" Visibility="{Binding Path=vSvc2}" />
</StackPanel>
</Border>
<Border BorderBrush="DimGray" BorderThickness="1" Margin="2,2,2,2">
<StackPanel Name="spSvcYel" *MouseUp*="Svc_MouseUp">
<TextBlock Name="txSvcYel" Height="14" Width="16" TextAlignment="Center" FontWeight="Normal" Text="{Binding Path=sSvc3}" Background="Yellow" Visibility="{Binding Path=vSvc3}" />
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
这导致一个很好的布局,根据信息填充细胞,从DB(显示左上角)来:
我需要每个单元(在G,O,Y突出显示)内的小方块陷阱点击。 我已经有一个整体的MouseUp处理程序ItemsControl
( wpSubMap_MouseUp
),它处理的细胞点击自己和正常工作。 我想新的处理程序添加到单个细胞的项目,而这也正是一切都停止工作:
如果我只留下Svc_MouseUp
-对于外部StackPanel
,周围所有的广场,它每次火灾; 但问题是检测到,该方实际上点击。
如果我启用Svc_MouseUp
-为内StackPanels
,包装个人广场,他们不火都!?
PS两者的MouseUp处理程序使用下面的模式来防止重入:
private void Svc_MouseUp( object sender, MouseButtonEventArgs e )
{
if( bMouseUp ) return;
Cursor cur= this.Cursor;
try
{
this.Cursor= Cursors.Wait;
bMouseUp= true;
.. /// do smth useful
}
finally
{
e.Handled= true;
bMouseUp= false;
this.Cursor= cur;
}
}
我缺少的是在这里吗? 是什么让处理器射击行为内如此不同StackPanels
?
而我应该如何有效地实现碰撞检测的内部StackPanels
?