我有一个奇怪的问题,我不知道如何解决。
我正在从头开始创建一个颜色选择器。我是通过创建一组用户控件并将它们放到“主控件”中来实现的。
例如,当用户在色相选择器上拖动时,我将鼠标向下,向上移动(在色相选择器用户控件内部)。
一个简单的布尔值指示实际发生的情况。
//Mouse down
_isDrag = true;
//Mouse Move
if(!_isDrag) return;
//Moving the position indicator shape thingy
//Calculating the hue
//Mouse Up
_isDrag = false;
Run Code Online (Sandbox Code Playgroud)
但是,如果鼠标向上发生在色相选择器的范围之外,则不会触发鼠标向上事件。因此,当用户返回到色相选择器的区域时,形状指示器就会运行。
我可以肯定答案在某处,但恐怕我的搜索技能无法胜任该任务。我不知道该找什么。
感谢您的时间。
解:
private bool _isDrag;
//Request Mouse capture for the Container
private void MsDown(object sender, MouseButtonEventArgs e)
{
_isDrag = true;
Mouse.Capture(MainContainer);
}
//Release Mouse capture
private void MsUp(object sender, MouseButtonEventArgs e)
{
_isDrag = false;
Mouse.Capture(null);
}
//Move the handle vertically along the main container, with respect to it's width …Run Code Online (Sandbox Code Playgroud)