選択効果を描画するために使用されるカスタムパネルがあります。しかし、画面が十分に大きい場合 (2 つのモニター間) にマウスを前後に移動すると、前の四角形がクリアされないことがあります。これは WPF のバグまたは制限ですか? この問題を解決する方法を知っていますか? 前もって感謝します。
簡略化されたコードは次のようになります
public class CustomPanel : Panel
{
private Rectangle _rectangle;
public CustomPanel()
{
this._rectangle = new Rectangle();
this._rectangle.StrokeThickness = 3;
this._rectangle.Stroke = new SolidColorBrush(Color.FromArgb(220, 0, 0, 0)); ;
this.Children.Add(this._rectangle);
}
protected override Size MeasureOverride(Size availableSize)
{
this._rectangle.Measure(availableSize);
return this._rectangle.DesiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
if (!finalSize.IsEmpty)
{
this._rectangle.Arrange(new Rect(new Point(0, 0), finalSize));
}
return finalSize;
}
}
このように、グリッドに配置して、マウスの移動中に無効にします
void OnMouseMove(object sender, MouseEventArgs e)
{
var point = e.GetPosition(this);
var size = new Size(point.X>=0? point.X:0, point.Y>=0? point.Y:0);
this.Selection.Measure(size);
this.Selection.Arrange(new Rect(size));
}
結果は次の図のようになります