Results 1 to 5 of 5

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User vanmx's Avatar
    Join Date: Oct:2006
    Location:
    Posts: 1,964

    WPF + 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));
                }
            }
        }
    }
    XAML -

    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 behind -

    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.MaxValue
    Last 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

  2. #2
    Registered User wp7guy's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 1,264
    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.

  3. #3
    Registered User vanmx's Avatar
    Join Date: Oct:2006
    Location:
    Posts: 1,964


    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

  4. #4
    Registered User wp7guy's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 1,264
    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.

  5. #5
    Registered User vanmx's Avatar
    Join Date: Oct:2006
    Location:
    Posts: 1,964
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |