解決策を見たときに明らかになる何かを見落としている可能性がありますが、今のところ...
Toolkit チャートのチャート領域内でカスタム カーソルを使用しようとしています。チャート用の ControlTemplate と、カーソルを含むグリッドを作成しました。カーソルを表示/非表示にし、さまざまなマウス イベントを使用して、含まれているグリッドを移動しようとします。カーソルは正しいタイミングで表示されていますが、正しい位置に移動できません。
ControlTemplate は次のとおりです (ファンキーな色は、テンプレートのさまざまな部分が何に関連するかを確認するための試みです)。
<dataVisTK:Title Content="{TemplateBinding Title}"
Style="{TemplateBinding TitleStyle}"/>
<Grid Grid.Row="1">
<!-- Remove the Legend -->
<!--<dataVisTK:Legend
x:Name="Legend"
Title="{TemplateBinding LegendTitle}"
Style="{TemplateBinding LegendStyle}"
Grid.Column="1"/>-->
<chartingPrimitivesTK:EdgePanel x:Name="ChartArea"
Background="#EDAEAE"
Style="{TemplateBinding ChartAreaStyle}"
Grid.Column="0">
<Grid Canvas.ZIndex="-1"
Background="#2008AE"
Style="{TemplateBinding PlotAreaStyle}">
</Grid>
<Border Canvas.ZIndex="1"
BorderBrush="#FF250010"
BorderThickness="3" />
<Grid x:Name="gridHandCursors"
Canvas.ZIndex="5"
Width="32" Height="32"
Visibility="Collapsed">
<Image x:Name="cursorGrab" Width="32"
Source="Resources/grab.png" />
<Image x:Name="cursorGrabbing" Width="32"
Source="Resources/grabbing.png"
Visibility="Collapsed"/>
</Grid>
</chartingPrimitivesTK:EdgePanel>
</Grid>
</Grid>
</Border>
マウス イベント (特に、MouseMove) は次のとおりです。
void TimelineChart_Loaded(object sender, RoutedEventArgs e)
{
chartTimeline.UpdateLayout();
List<FrameworkElement> chartChildren = GetLogicalChildrenBreadthFirst(chartTimeline).ToList();
mChartArea =
chartChildren.Where(element => element.Name.Equals("ChartArea")).FirstOrDefault() as Panel;
if (mChartArea != null)
{
grabCursor = chartChildren.Where(element => element.Name.Equals("cursorGrab")).FirstOrDefault() as Image;
grabbingCursor = chartChildren.Where(element => element.Name.Equals("cursorGrabbing")).FirstOrDefault() as Image;
mGridHandCursors =
chartChildren.Where(element => element.Name.Equals("gridHandCursors")).FirstOrDefault() as Grid;
mChartArea.Cursor = Cursors.None;
mChartArea.MouseMove += new MouseEventHandler(mChartArea_MouseMove);
mChartArea.MouseLeftButtonDown += new MouseButtonEventHandler(mChartArea_MouseLeftButtonDown);
mChartArea.MouseLeftButtonUp += new MouseButtonEventHandler(mChartArea_MouseLeftButtonUp);
if (mGridHandCursors != null)
{
mChartArea.MouseEnter += (s, e2) =>
mGridHandCursors.Visibility = Visibility.Visible;
mChartArea.MouseLeave += (s, e2) =>
mGridHandCursors.Visibility = Visibility.Collapsed;
}
}
}
void mChartArea_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (grabCursor != null)
grabCursor.Visibility = Visibility.Visible;
if (grabbingCursor != null)
grabbingCursor.Visibility = Visibility.Collapsed;
}
void mChartArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (grabCursor != null)
grabCursor.Visibility = Visibility.Collapsed;
if (grabbingCursor != null)
grabbingCursor.Visibility = Visibility.Visible;
}
void mChartArea_MouseMove(object sender, MouseEventArgs e)
{
if (mGridHandCursors != null)
{
Point pt = e.GetPosition(null);
mGridHandCursors.SetValue(Canvas.LeftProperty, pt.X);
mGridHandCursors.SetValue(Canvas.TopProperty, pt.Y);
}
}
この障害を乗り越えて助けていただければ幸いです。
ありがとう、wTs