C#WPF在UserControl中绘制OxyPlot

用户名

我想在UserControl中使用OxyPlot绘制坐标系。不幸的是,有两个错误。我不知道他们为什么站在那儿。然后,当我按下MainWindow应用程序中的某个按钮时,此UserControl便会出现在我的MainWindow中。

有人可以告诉我错误在哪里并解决吗?

这可以在另一个应用程序中使用。这也不是UserControl,而是MainWindow。

错误:

  • “ UCScreen”不包含“ Title”的定义,并且您无法找到接受第一个UCVoucher类型参数的标题扩展方法

  • 名称“创建者”在当前上下文中不存在。

我已经用注释标记了代码中的错误

用户控件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using OxyPlot;
using OxyPlot.Series;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
using System.Globalization;

namespace Vorschau
{
    /// <summary>
    /// Interaktionslogik für UCVorschau.xaml
    /// </summary>
    public partial class UCVorschau : UserControl
    {
        public UCVorschau()
        {
            InitializeComponent();
            DataContext = this; //Here is an error
            this.Title = "Vorschaubild";
        }

        public IList<DataPoint> Points { get; private set; }

        /// <summary>
        /// Einstelungs-Fenster wird geöffnet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //btEinstellung


        private void btGenerate_Click(object sender, RoutedEventArgs e)
        {
            DateTime startZeit = DateTime.Now;
            Cursor = Cursors.Wait;

            double zufallszahlX;
            double zufallszahlY;

            double XMax = 10;
            double XMin = 0;
            double YMax = 10;
            double YMin = 0;
            // Zur Erstellung des Seeds
            int h = DateTime.Now.Hour;
            int m = DateTime.Now.Minute;
            int s = DateTime.Now.Second;
            String u = h.ToString() + m.ToString() + s.ToString();
            int iu = Int32.Parse(u);
            Random zufall = new Random(iu);
            Console.WriteLine("______________");
            CultureInfo en = new CultureInfo("en-US", false); // Damit ein Punkt ist anstatt ein Komma
            DataContext = this;
            this.Points = new List<DataPoint>();
            System.IO.File.WriteAllText(((Environment.CurrentDirectory + @"\files\koordinaten.txt")), string.Empty);
            using (var fileStream = new FileStream(String.Format(Environment.CurrentDirectory + @"\files\koordinaten.txt"), FileMode.OpenOrCreate))
            using (var streamWriter = new StreamWriter(fileStream))
            {
                for (int i = 1; i <= 10; i++)
                {
                    zufallszahlX = zufall.NextDouble() * (XMax - XMin) + XMin;
                    zufallszahlY = zufall.NextDouble() * (YMax - YMin) + YMin;
                    //Console.WriteLine("( " + zufallszahlX + " / " + zufallszahlY + " )" + " |" + i);
                    streamWriter.WriteLine("( " + zufallszahlX.ToString(en.NumberFormat) + " / " + zufallszahlY.ToString(en.NumberFormat) + " )" + " |" + i);
                    creator.addPoint(zufallszahlX, zufallszahlY); //Here is an error
                    Points.Add(new DataPoint(zufallszahlX, zufallszahlY));
                }
                ls.ItemsSource = Points;
            }
            Cursor = Cursors.Arrow;
            DateTime endZeit = DateTime.Now;
            TimeSpan gemesseneZeit = endZeit - startZeit;
           // statusbar.Text = "Gemessen Zeit für den Durchlauf: " + gemesseneZeit;
        }
    }
}

<UserControl x:Class="Vorschau.UCVorschau"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Vorschau"
             xmlns:oxy="http://oxyplot.org/wpf"
             mc:Ignorable="d" Height="461" Width="624">
    <Canvas HorizontalAlignment="Left" Height="461" VerticalAlignment="Top" Width="624">
        <Button x:Name="btGenerate" Content="Generiere Koordinaten" Canvas.Left="25" Canvas.Top="409" Click="btGenerate_Click"/>
        <oxy:Plot x:Name="oxyPlot" Title="{Binding Title}" Height="245" Canvas.Left="298" Canvas.Top="32" Width="273" Background="#FFD1CFD0">
            <oxy:Plot.Series>
                <oxy:LineSeries x:Name="ls" ItemsSource="{Binding Points}" LineStyle="None"  MarkerType="Square" MarkerSize="5" MarkerFill="Black"/>
            </oxy:Plot.Series>

        </oxy:Plot>
    </Canvas>
</UserControl>
毫米8

UserControl班有没有Title财产,但Plot类有。您可能要设置一个:

public UCVorschau()
{
    InitializeComponent();
    DataContext = this; //Here is an error
    oxyPlot.Title = "Vorschaubild";
}

或者您应该TitleUserControl类中添加一个属性

public UCVorschau()
{
    InitializeComponent();
    DataContext = this; //Here is an error
    this.Title = "Vorschaubild";
}

public string Title { get; set; }

然后,您在XAML标记中定义的绑定将起作用。

关于“创造者”,我不知道那是什么。由于您正在将,添加DataPointPoints集合中,因此我也建议删除此行。或者,您可以将DataPoint直接添加LineSeries在XAML标记中定义的“ ls”中:

ls.addPoint(zufallszahlX, zufallszahlY);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在C#WPF中绘制多点线

来自分类Dev

C#WPF:将UserControl放在DataGridRow中

来自分类Dev

如何使用XAML在C#WPF中绘制弹簧

来自分类Dev

C#WPF订阅从UserControl触发的另一个类中的事件

来自分类Dev

在OxyPlot WPF上绘制

来自分类Dev

C#WPF XAML在UserControl负载上运行XAML命令

来自分类Dev

C#WPF中的TreeView目录

来自分类Dev

在C#WPF中实现INotifyPropertyChanged

来自分类Dev

图像未在C#WPF中显示

来自分类Dev

在C#WPF中更新SQL记录

来自分类Dev

C#WPF中的随机颜色

来自分类Dev

WrapPanel中的C#WPF控件

来自分类Dev

C#WPF中DLL的资源字典

来自分类Dev

C#WPF中的TreeView目录

来自分类Dev

C#WPF中的随机颜色

来自分类Dev

DataGrid中的TextAlignment-> C#WPF

来自分类Dev

C#WPF中的System.InvalidOperationException

来自分类Dev

如何在C#Wpf UserControl中使用F#对象/记录

来自分类Dev

如何在C#WPF中向Datagrid添加行

来自分类Dev

在C#WPF中的滑块上添加直方图

来自分类Dev

如何在C#WPF中以重复模式运行MediaPlayer?

来自分类Dev

c#WPF中的文字字符过多

来自分类Dev

C#WPF在XAML中添加KeyBinding事件

来自分类Dev

C#WPF中的“简单MVVM Toolkit”子模型类

来自分类Dev

在C#WPF应用程序中处理线程

来自分类Dev

C#WPF中的函数内的后台工作程序

来自分类Dev

如何在Datagrid C#WPF中动态行?

来自分类Dev

xmlns:dc在C#WPF中是什么意思?

来自分类Dev

如何在C#WPF中以编程方式创建DataGrid?