第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

UWP使用事件繪制沒有XAML的線

UWP使用事件繪制沒有XAML的線

C#
慕運維8079593 2022-01-16 16:16:11
我對 UWP 還很陌生。我目前正在開發(fā)一個應用程序,該應用程序使用 Grid 在主頁中制作的事件來測試我正在記錄按鍵的觸摸屏完整性和功能。Grid 有一個名稱grid我正在使用事件偵聽器:Grid_pointermoved和Grid_PointerReleased相應地獲取進行滑動的路徑數(shù)組,以便我可以分析路徑。這部分已經(jīng)制作完成,目前運行良好。我嘗試了什么:現(xiàn)在我需要在正在滑動的屏幕上畫一條線。我試圖谷歌并找到一些關(guān)于它的信息,但我無法找到任何關(guān)于如何根據(jù)我剛剛從事件監(jiān)聽器獲得的坐標繪制一條線的解決方案。此外,我還有一個單獨的事件,它停止記錄滑動,這個事件也應該能夠從以前制作的任何行中清除屏幕。由于每個測試都有不同數(shù)量的行,我也不能事先對行對象進行硬編碼。歡迎任何有關(guān)如何在不使用 XAML 的情況下簡單地畫線并依賴于已創(chuàng)建事件的適當幫助。
查看完整描述

2 回答

?
PIPIONE

TA貢獻1829條經(jīng)驗 獲得超9個贊

這是給你的demo,希望對你有幫助。


XAML 頁面:


<Grid x:Name="rootGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">


</Grid>

后面的代碼:


public sealed partial class MainPage : Page

{

    public MainPage()

    {

        this.InitializeComponent();

        rootGrid.PointerPressed += RootGrid_PointerPressed;

        rootGrid.PointerMoved += RootGrid_PointerMoved;

        rootGrid.PointerReleased += RootGrid_PointerReleased;

        rootGrid.PointerExited += RootGrid_PointerExited;

    }


    int pointerId = -1;

    Line curLine = null;


    private void RootGrid_PointerExited(object sender, PointerRoutedEventArgs e)

    {

        OnComplete();

    }


    private void RootGrid_PointerReleased(object sender, PointerRoutedEventArgs e)

    {

        OnComplete();

    }


    private void OnComplete()

    {

        // reset pointerId so that other pointers may enter live rendering mode

        pointerId = -1;

        curLine = null;

    }


    private void RootGrid_PointerMoved(object sender, PointerRoutedEventArgs e)

    {

        var pointerPoint = e.GetCurrentPoint(rootGrid);


        if (pointerId == (int)pointerPoint.PointerId)

        {

            curLine.X2 = pointerPoint.Position.X;

            curLine.Y2 = pointerPoint.Position.Y;

            curLine.Stroke = new SolidColorBrush(Colors.Red);

        }

    }


    private void RootGrid_PointerPressed(object sender, PointerRoutedEventArgs e)

    {

        // Make sure no pointer is already drawing (we allow only one 'active' pointer at a time)

        if (pointerId == -1)

        {

            var pointerPoint = e.GetCurrentPoint(rootGrid);

            if (!pointerPoint.Properties.IsLeftButtonPressed)

                return;


            curLine = new Line();

            var position = pointerPoint.Position;

            curLine.X1 = pointerPoint.Position.X;

            curLine.Y1 = pointerPoint.Position.Y;

            curLine.StrokeThickness = 1;


            rootGrid.Children.Add(curLine);


            //save pointer id so that no other pointer can ink until this one is released

            pointerId = (int)pointerPoint.PointerId;

        }

    }

}


查看完整回答
反對 回復 2022-01-16
?
九州編程

TA貢獻1785條經(jīng)驗 獲得超4個贊

您有一個點集合,您可以從這些點繪制一條折線并將其添加到網(wǎng)格中。


private void CreatePolyline()

{

    // Initialize a new Polyline instance

    Polyline polyline = new Polyline();


    // Set polyline color

    polyline.Stroke = new SolidColorBrush(Colors.Black);


    // Set polyline width/thickness

    polyline.StrokeThickness = 10;


    // Initialize a point collection

    var points = new PointCollection();

    points.Add(new Point(20, 100));

    points.Add(new Point(35, 150));

    points.Add(new Point(60, 200));

    points.Add(new Point(90, 250));

    points.Add(new Point(40, 300));


    // Set polyline points

    polyline.Points = points;


    // Finally, add the polyline to layout

    grid.Children.Add(polyline);

}

或者,為了測試觸摸屏的完整性,您可以使用另一個用戶控件InkCanvas,而無需以編程方式繪制線條。


首先,刪除你所做的所有代碼,這樣你就有了一個空白的 Grid 'grid'。


在設計器中,將InkCanvas控件拖動到“網(wǎng)格”。


并從后面的代碼啟用觸摸功能:


inkCanvas.InkPresenter.InputDeviceTypes = Windows.UI.Core.CoreInputDeviceTypes.Touch;

就這些。


要清除 中的墨水,您可以在您提到的單獨事件InkCanvas中簡單地調(diào)用它,


inkCanvas.InkPresenter.StrokeContainer.Clear();


查看完整回答
反對 回復 2022-01-16
  • 2 回答
  • 0 關(guān)注
  • 181 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號