如何在Wpf中创建多行可编辑数字信号/方波?

问题描述 投票:0回答:1

我正在执行一项任务,需要一个页面来编辑数字信号/方波并保存它们。但数据量太大,百万级数据下控件无法发挥作用。

如图所示,我尝试使用datagrid,当列数限制在100左右时,datagrid可以表现良好,但任务将有数百万列。 enter image description here 我想知道是否还有其他解决方案,有人可以帮助我吗?

c# wpf
1个回答
0
投票

这是示例代码:

    <Window x:Class="YourNamespace.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Digital Signal Waveform" Height="350" Width="525">
    <Grid>
        <Canvas x:Name="signalCanvas" Background="White" Width="500" Height="200" Margin="10"/>
    </Grid>
</Window>

此示例使用折线来表示画布上的数字信号。鼠标事件用于允许用户绘制和编辑波形。您可以根据您的具体要求进一步定制此示例。

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace YourNamespace
{
    public partial class MainWindow : Window
    {
        private Polyline signalLine;
        private PointCollection signalPoints;

        public MainWindow()
        {
            InitializeComponent();
            InitializeSignal();
        }

        private void InitializeSignal()
        {
            signalLine = new Polyline
            {
                Stroke = Brushes.Black,
                StrokeThickness = 2
            };

            signalPoints = new PointCollection();
            signalLine.Points = signalPoints;

            signalCanvas.Children.Add(signalLine);
            signalCanvas.MouseDown += SignalCanvas_MouseDown;
            signalCanvas.MouseMove += SignalCanvas_MouseMove;
            signalCanvas.MouseUp += SignalCanvas_MouseUp;
        }

        private void SignalCanvas_MouseDown(object sender, MouseButtonEventArgs e)
        {
            AddPoint(e.GetPosition(signalCanvas));
        }

        private void SignalCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                AddPoint(e.GetPosition(signalCanvas));
            }
        }

        private void SignalCanvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            // Perform any cleanup or finalization if needed
        }

        private void AddPoint(Point point)
        {
            signalPoints.Add(new Point(point.X, signalCanvas.ActualHeight / 2));
            signalLine.Points = signalPoints;
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.