6 Replies Latest reply on Apr 19, 2017 1:10 PM by gregor

    How can I create an AF picker object in a WPF window?

    TaoIPE

      How can I create PI/AF pickers objects in a WPF window like what we had in Forms. Do we have example code of this kind?

      Thanks,

        • Re: How can I create an AF picker object in a WPF window?
          gregor

          Hello Tao,

           

          If your question is related to how to create a WPF application, you will find a bunch of WPF tutorials in the Internet.

          In case your question is specific to AF SDK, can you please ask more detailed? Are you e.g. looking for a way to retrieve a list of known servers?

            • Re: How can I create an AF picker object in a WPF window?
              TaoIPE

              Hey, Gregor,

              Yes, my question is specific to AF SDK. I want to build a windows form dialog in WPF to retrieve a list of known servers and connect to one of them.

                • Re: How can I create an AF picker object in a WPF window?
                  Nocodes79

                  Hi Tao,

                   

                  I think this is a more general question: how can I embed WindowsForms Controls in a WPF application?

                  In my solution I would first create a Windows Form with all the Windows Forms controls I need.

                  Then I would create a WPF application and embed the Windows Form rpeviously created.

                   

                  Hre goes how to embed Windows Forms controls in WPF:

                  https://www.dotnetperls.com/windowsformshost-wpf

                  • Re: How can I create an AF picker object in a WPF window?
                    gregor

                    Hello Tao,

                     

                    Please see below sample. If you are connecting against a Collective, the Collective property will have the name of the Collective, otherwise it will be null. Please note that it is usually not necessary to call Connect, Disconnect methods as AF SDK is handling connections internally when requests for data are send. This may be different with your application if the user should be allowed to switch between servers.

                     

                            static void Main(string[] args)
                            {
                                // Create an object of known AF Servers 
                                OSIsoft.AF.PISystems knownPISystems = new OSIsoft.AF.PISystems();
                                // Iterate through the list
                                Console.WriteLine("List of known AF Servers");
                                foreach (OSIsoft.AF.PISystem piSystem in knownPISystems)
                                {
                                    Console.WriteLine(" -> {0}", piSystem.Name);
                                }
                                // Connect to an AF Server by its name
                                string afServerHost = "AFServer";
                                OSIsoft.AF.PISystem afServer = knownPISystems[afServerHost];
                                afServer.Connect();
                                Console.WriteLine();
                                // Create an object of known PI Data Archives 
                                OSIsoft.AF.PI.PIServers knownPIDataArchives = new OSIsoft.AF.PI.PIServers();
                                // Iterate through the list
                                Console.WriteLine("List of known PI Data Archives Servers");
                                foreach (OSIsoft.AF.PI.PIServer piServer in knownPIDataArchives)
                                {
                                    Console.WriteLine(" -> {0}", piServer.Name);
                                }
                                // Connect to an PI Data Archive by its name
                                string piDataArchiveHost = "PIServer";
                                OSIsoft.AF.PI.PIServer piDataArchive = knownPIDataArchives[piDataArchiveHost];
                                piDataArchive.Connect();
                                Console.WriteLine();
                                Console.Write("Done. Press any key to quit .. ");
                                Console.ReadKey();
                            }
                    
                  • Re: How can I create an AF picker object in a WPF window?
                    Jaison_Rodrigues

                    Hi Gregor,

                     

                    How can we add controls like AFDatabasePicker, PISystemPicker controls that are part of OSIsoft.AF.UI library to a WPF application?

                     

                    They load perfectly fine for Windows Form but are not available while creating a WPF application.

                     

                    Regards,

                    Jaison Rodrigues

                      • Re: How can I create an AF picker object in a WPF window?
                        gregor

                        Hello Jaison,

                         

                        OSIsoft.AF.UI.dll, the assembly containing the controls you mention is a .NET library.

                         

                        My earlier understanding was that WPF is the client version of Silverlight but I found this resource which does a better job in Contrasting Silverlight and WPF

                        One of the major difference is the .NET Framework support. Silverlight only supports .NET Framework for Silverlight while according to the before mentioned resource WPF supports .NET Framework.

                         

                        A core sentence related to your question is: Windows Presentation Foundation (WPF) provides developers with a unified programming model for building rich Windows Forms applications that incorporate user interface (UI) ...

                         

                        Well, this tells me what you like to do should be possible: Using Windows Forms controls offered by OSIsoft.AF.UI.dll in your WPF application. The Walkthrough: Hosting a Windows Forms Control in WPF describes how this is done.