IToolS Blog

Using IToolS in WPF

by itools@albertoschiassi.it on domenica 1 febbraio 2015 03:37
In questo esempio viene mostrato come utilizzare i componenti IToolS in WPF mediante il pattern MVVM: 

<Window x:Class="TestIToolSWpfMVVM.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:TestIToolSWpfMVVM"
        Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
        <local:ViewModel/>
    Window.DataContext>
    <Grid>
        <ListView Name="ListViewGroup" ItemsSource="{Binding Group}"  >
            <ListView.View>
                <GridView x:Name="grdTest">
                    <GridViewColumn Header="VariableName" DisplayMemberBinding="{Binding VariableName}"  Width="100"/>
                    <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Value}"  Width="100" />
                    <GridViewColumn Header="Address" DisplayMemberBinding="{Binding Address}" Width="100" />
                    <GridViewColumn Header="Area" DisplayMemberBinding="{Binding Area}" Width="100" />
                    <GridViewColumn Header="VariableType" DisplayMemberBinding="{Binding VariableType}" Width="100" />
                <GridView>
            <ListView.View>
        <ListView>
    <Grid>
<Window>

 

ViewModel:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace TestIToolSWpfMVVM
{
   public class ViewModel
   {
      private IToolS.Components.Communication.Group m_group;
      private IToolS.Components.Communication.Variable m_variable1;
      private IToolS.Components.Communication.Variable m_variable2;
      private IToolS.Components.Communication.Client m_client;
      private IToolS.Components.IOServers.IOServer m_ioServer;
 
      public ViewModel()
      {
         m_variable1 = new IToolS.Components.Communication.Variable() { VariableName = "var1", Address = "0", Area = "HR" };
         m_variable2 = new IToolS.Components.Communication.Variable() { VariableName = "var2", Address = "1", Area = "HR" };
 
         m_group = new IToolS.Components.Communication.Group();
         m_group.Items.AddRange(new IToolS.Components.Communication.Variable[] { m_variable1, m_variable2 });
 
         m_ioServer = new IToolS.Components.IOServers.IOServer() { Name = "Simulation" };
 
         m_client = new IToolS.Components.Communication.Client();
         m_client.IOServer = m_ioServer;
         m_client.Group = m_group;
 
         m_client.Start();
 
      }
 
      public IToolS.Components.Communication.Group Group
      {
         get { return m_group; }
         set { m_group = value; }
      }
 
   }
}
TestIToolSWpfMVVM.zip

Blogs Parent Separator IToolS Blog
Author

Tags