用拇指拖动wpf窗口:可以透明吗?

发布于 2024-07-14 15:58:59 字数 534 浏览 5 评论 0原文

我一直在测试 Blu 并且我注意到我可以拖动窗口。 这个窗口是透明的。 我尝试用拇指做同样的事情,但我不知道如何使其透明。 窗口的其余部分是透明的,但拇指不是。

有没有办法让拇指透明,或者我应该使用其他技术?

我使用这个活动:

 private void DragThumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
    {
        Canvas.SetLeft(this, Canvas.GetLeft(this) + e.HorizontalChange);
        Canvas.SetTop(this, Canvas.GetTop(this) + e.VerticalChange);
    }

谢谢

I've been testing Blu and I noticed that I could drag the window. This window is transparent. I tried to do the same with a Thumb, but I don't know how to make it transparent. The rest of the window is transparent, but the thumb is not.

Is there any way to make the thumb transparent, or should I use another technique?

I use this event:

 private void DragThumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
    {
        Canvas.SetLeft(this, Canvas.GetLeft(this) + e.HorizontalChange);
        Canvas.SetTop(this, Canvas.GetTop(this) + e.VerticalChange);
    }

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

许你一世情深 2024-07-21 15:58:59

您可以使用不透明度属性将拇指控件设为不可见。

Opacity="1"(完全可见)

Opacity="0"(不可见)

来自我的应用程序的示例

        <Thumb Name="myThumb"
               Width="10"
               Height="10"
               DragDelta="onDragDelta"
               DragStarted="onDragStarted"
               DragCompleted="onDragCompleted"
               Margin="5"
               HorizontalAlignment="Right"
               Opacity="1">

        </Thumb>

You can turn a thumb control invisible with the Opacity attribute.

Opacity="1" (full visible)

or

Opacity="0" (not visible)

Sample from my application

        <Thumb Name="myThumb"
               Width="10"
               Height="10"
               DragDelta="onDragDelta"
               DragStarted="onDragStarted"
               DragCompleted="onDragCompleted"
               Margin="5"
               HorizontalAlignment="Right"
               Opacity="1">

        </Thumb>
对你再特殊 2024-07-21 15:58:59

不确定我是否正确理解您的问题,但是要拖动 wpf 窗口,您需要在表单(或表单本身)上的组件的单击事件处理程序中键入:

this.DragMove();

无需自己实现拖动功能。


更新:小例子:创建一个窗口,在其中放置一个按钮。 将窗口的 MouseDown 和按钮的 Click 连线如下:

    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
    this.DragMove();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("hey");
}

工作完美,您可以拖动窗口,按钮继续工作...

Not sure if I understand your question correctly, but to drag a wpf window, all you need to type in the click event handler of a component on the form (or the form itsself) is:

this.DragMove();

There is no need to implement the dragging functionality yourself.


Update: small example: Create a window, place a button in it. Wire the MouseDown of the window and the Click of the button as:

    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
    this.DragMove();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("hey");
}

Works perfectly, you can drag the window, and the button continues to work...

难如初 2024-07-21 15:58:59

或者,您可以将 Thumb 控件的控件模板设置为“透明”,如下代码片段:

<Canvas Background="LightGray">
    <Grid Canvas.Left="451" Canvas.Top="148" Width="120" Height="120" Background="Red">
        <Thumb DragDelta="Thumb_DragDelta" Cursor="SizeAll"
               DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}}">
            <Thumb.Template>
                <ControlTemplate>
                    <Grid>
                        <Ellipse Fill="Black" Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                        <Rectangle Fill="Transparent" />
                    </Grid>
                </ControlTemplate>
            </Thumb.Template>
        </Thumb>
        <Ellipse Fill="Pink" Height="100" Width="100" IsHitTestVisible="False" />
    </Grid></Canvas>

DragDelta 事件:

private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
    var thumb = (System.Windows.Controls.Primitives.Thumb)sender;
    var grid = (Grid)(thumb.DataContext);
    if (grid == null) return;
    var left = Canvas.GetLeft(grid);
    var top = Canvas.GetTop(grid);
    Canvas.SetLeft(grid, left + e.HorizontalChange);
    Canvas.SetTop(grid, top + e.VerticalChange);
}

< img src="https://i.sstatic.net/3rLw0.png" alt="在此处输入图像描述">

Optionally, you can set control template of Thumb control as 'Transparent', as following snippet code:

<Canvas Background="LightGray">
    <Grid Canvas.Left="451" Canvas.Top="148" Width="120" Height="120" Background="Red">
        <Thumb DragDelta="Thumb_DragDelta" Cursor="SizeAll"
               DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}}">
            <Thumb.Template>
                <ControlTemplate>
                    <Grid>
                        <Ellipse Fill="Black" Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                        <Rectangle Fill="Transparent" />
                    </Grid>
                </ControlTemplate>
            </Thumb.Template>
        </Thumb>
        <Ellipse Fill="Pink" Height="100" Width="100" IsHitTestVisible="False" />
    </Grid></Canvas>

DragDelta event:

private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
    var thumb = (System.Windows.Controls.Primitives.Thumb)sender;
    var grid = (Grid)(thumb.DataContext);
    if (grid == null) return;
    var left = Canvas.GetLeft(grid);
    var top = Canvas.GetTop(grid);
    Canvas.SetLeft(grid, left + e.HorizontalChange);
    Canvas.SetTop(grid, top + e.VerticalChange);
}

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文