Results 1 to 5 of 5
Thread: WPF + XAML + .
Hybrid View
-
10th December 2017 16:19 #1
WPF + XAML + .
. ,
. :
:
XAML -Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace Inspector { class MyCommPort : INotifyPropertyChanged { SerialPort serialPort = null; public string TestText = ""; public MyCommPort() { serialPort = new SerialPort("COM7", 9600); serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler); serialPort.Open(); } ~MyCommPort() { serialPort.Close(); } private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e) { SerialPort sp = (SerialPort)sender; string testString = null; string indata = sp.ReadLine(); TestText = indata; } // Extend the INotifyPropertyChanged interface public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } }
code behind -Code:<Window x:Class="Inspector.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Inspector" mc:Ignorable="d" Title="MainWindow" Height="720" Width="1280"> <Grid <Paragraph> <TextBlock Name="TestText" Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=TestText}"></TextBlock> </Paragraph> </Grid> </Window>
Code: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 System.ComponentModel; using System.IO.Ports; namespace Inspector { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); TestText.DataContext = new MyCommPort(); } } }
e . Arduino 0 int.MaxValueLast edited by vanmx; 10th December 2017 at 16:49.
X470 AORUS ULTRA GAMING | Ryzen5 2600 |2x16GB Corsair LPX 3200Mhz | EVGA GeForce GTX 1080 Ti SC Black Edition Gaming|512GB Samsung 970 Pro +
512GB ADATA SU800| Corsair HX1200i | Corsair Graphite 600t |BENQ PD3200U
-
11th December 2017 15:25 #2
MyCommPort OnPropertyChanged. , XAML-a. DataReceivedHandler .
OnPropertyChanged (nameof(TestText));"The only way to discover the limits of the possible is to go beyond them into the impossible." - Arthur C. Clarke's second low.
-
12th December 2017 11:02 #3
Code:private string testText; public string TestText { get { return this.testText } set { this.testText = value; OnPropertyChanged("TestText"); } }X470 AORUS ULTRA GAMING | Ryzen5 2600 |2x16GB Corsair LPX 3200Mhz | EVGA GeForce GTX 1080 Ti SC Black Edition Gaming|512GB Samsung 970 Pro +
512GB ADATA SU800| Corsair HX1200i | Corsair Graphite 600t |BENQ PD3200U
-
12th December 2017 12:57 #4
TestText string.Empty null.
"The only way to discover the limits of the possible is to go beyond them into the impossible." - Arthur C. Clarke's second low.
-
12th December 2017 17:42 #5
sp.ReadLine() sp.ReadExisting() .
.
X470 AORUS ULTRA GAMING | Ryzen5 2600 |2x16GB Corsair LPX 3200Mhz | EVGA GeForce GTX 1080 Ti SC Black Edition Gaming|512GB Samsung 970 Pro +
512GB ADATA SU800| Corsair HX1200i | Corsair Graphite 600t |BENQ PD3200U




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in