私は非常に簡単にsmthを達成する方法を見つけることができないようです:
内部に があり、アイテムを次のように配置し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 で強調表示) のクリックをトラップする必要があります。セル自体のクリックを処理し、適切に動作するItemsControl
( )全体の MouseUp ハンドラーが既にあります。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;
}
}
ここで何が欠けていますか?ハンドラーの起動動作が inner で大きく異なるのはStackPanels
なぜですか?
また、inner のヒット検出を効率的に実装するにはどうすればよいStackPanels
ですか?