キャンバスに株のグラフを描きたいのですが。
キャンバスの初期サイズは、300(高さ)x 1000(幅)としましょう。
キャンバスの視覚的な部分に収まるように、在庫はさらに数日間取引されています。キャンバスの視覚的な部分
をドラッグ(スクロール)して、「背後」に隠れている非視覚的な部分を確認したいと思います。つまり、最初に支払われていない取引日を参照してください。
私を正しい道に導くためのアイデアや指針をいただければ幸いです。
2つのキャンバス(キャンバス内のキャンバス)を使用できます。外側のキャンバスのサイズは固定されていますが(1000 x 300)、内側のキャンバスは必要な大きさになります。ClipToBounds
外側のキャンバスのプロパティをに設定しますTrue
。
C#:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Stock
{
/// <summary>
/// Interaction logic for ListBox.xaml
/// </summary>
public partial class Chart : Window
{
private Point _capturePoint;
private double _captureLeft;
private double _captureTop;
public Chart()
{
InitializeComponent();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
_capturePoint = e.GetPosition(chart);
_captureLeft = Canvas.GetLeft(chart);
_captureTop = Canvas.GetTop(chart);
if (_capturePoint.X > 0 && _capturePoint.X < chart.RenderSize.Width &&
_capturePoint.Y > 0 && _capturePoint.Y < chart.RenderSize.Height)
{
CaptureMouse();
}
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
ReleaseMouseCapture();
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (Mouse.Captured == this)
{
var currentPoint = e.GetPosition(chart);
var diff = Point.Subtract(currentPoint, _capturePoint);
Canvas.SetTop(chart, _captureTop + diff.Y);
Canvas.SetLeft(chart, _captureLeft + diff.X);
}
}
}
}
XAML:
<Window x:Class="Stock.Chart"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ListBox" Height="300" Width="300">
<Canvas Height="300" Width="1000" x:Name="viewport" ClipToBounds="True">
<Canvas x:Name="chart" Background="Green" Width="2000" Height="1000" Canvas.Top="20" Canvas.Left="10" >
</Canvas>
</Canvas>
</Window>