我是WPF應用程序中的初學者,所以要仁慈。WPF如何在文本框中給出一個無效方法
我試圖重寫一個控制檯應用程序到WPF。要點是,如何在wpf中編寫方法,這是一種無效的方法。
我對代碼發表評論,我覺得它更易於理解。
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 Easy2AcquireCom;
using System.ComponentModel;
namespace WPF_Polling
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
IDeviceManager DeviceManager = new DeviceManager();
IDevice TheDevice = new Device();
Initialize initialisieren = new Initialize();
public MainWindow()
{
InitializeComponent();
this.DataContext = initialisieren;
initialisieren.InitializeDeviceManager(TheDevice, DeviceManager);
ListPrefix(); //???? Do I have to give the parameters?
}
private void ListPrefix(object sender, DependencyPropertyChangedEventArgs e) // that was a helper DataContextChanged helper
{
initialisieren.ListDevices(TheDevice,"device");
}
}
public class Initialize
{
public void InitializeDeviceManager(IDevice thedevice, DeviceManager devicemanager)
{
try
{
devicemanager.Initialize("");
int result = devicemanager.Setup(0);
thedevice = devicemanager.GetCurrentDevice();
thedevice.ClearComponentFilter();
}
catch (Exception error)
{
}
}
public void ListDevices(IDevice theDevice, string prefix)
{
string[] Tags = (string[]) theDevice.GetTagsByPrefix(prefix);
int Index = 1;
foreach (string Tag in Tags)
{ //I want to give out These Things in a TextBox or block
string Name = theDevice.GetTagName(Tag);
//Console.Write(" ");
//Console.Write(Index);
//Console.Write(" ");
//Console.Write(Tag);
//Console.Write(" (");
//Console.Write(Name);
//Console.WriteLine(")");
Index = Index + 1;
}
}
}
}
請參閱我已編輯的答案。 – mm8