8 Replies Latest reply on Feb 21, 2017 3:01 AM by TaoIPE

    AFDatabasePicker

    TaoIPE

      How do I add an AFDatabasePicker control (like what we have in PI System Explorer) in my .NET WPF UI?

        • Re: AFDatabasePicker
          tramachandran

          The AFDatabasePicker control is available in the OSISOFT.AF.UI library. Once you add this reference to your project you will be able to choose that item from the toolbox.

          Our learning channel video has a demo of this (~9:30) Introduction to AF SDK

          1 of 1 people found this helpful
            • Re: AFDatabasePicker
              TaoIPE

              I can easily add the OSIsoft controls in a Windows Forms application, but am having trouble adding the controls into my Windows WPF application. Any ideas how?

                • Re: AFDatabasePicker
                  Rhys Kirk

                  You can't do it at design time...well unless you have some kind of wrapper.

                  However, if you have a container where you want the control placed then you can do it via code...basically hosting in as a Win Forms control within WPF.

                   

                  I just put one on the Grid...you need to reference "WindowsFormsIntegration" and "System.Windows.Forms" in your WPF application, then you can do the following type of thing...

                   

                  private void Window_Loaded(object sender, RoutedEventArgs e)
                          {
                              System.Windows.Forms.Integration.WindowsFormsHost host =
                                  new System.Windows.Forms.Integration.WindowsFormsHost();
                  
                              OSIsoft.AF.UI.PISystemPicker WhichPISystem = new OSIsoft.AF.UI.PISystemPicker();
                  
                              host.Child = WhichPISystem;
                  
                              this.Grid1.Children.Add(host);
                          }
                  

                   

                  It just means you need to manage events etc directly in code rather than in the XAML designer.

                  2 of 2 people found this helpful
                    • Re: AFDatabasePicker
                      TaoIPE

                      Great! I have added the Windows Forms Control in a WPF grid.

                      However, can I build a WPF custom control for AF and PI server picker? Where are all the icons used in the Windows Forms AF/PI controls? I want to reuse them in my WPF custom control.

                    • Re: AFDatabasePicker
                      Eugene Lee

                      Hi Tao,

                       

                      You can do it like this.

                      Add assemblies:

                      1.AFSDK

                      2.AF UI

                      3.WindowsFormsIntegration

                      4.System.Windows.Forms

                       

                      Include this code in the Window Loaded event.

                       

                      WindowsFormsHost host =new WindowsFormsHost();
                      AFDatabasePicker picker = new AFDatabasePicker();
                      PISystem sys = new PISystems().DefaultPISystem;
                      picker.SetPISystem(sys,sys.Databases.DefaultDatabase);
                      host.Child = picker;
                      this.grid1.Children.Add(host);
                      

                       

                      where grid1 is the name of a grid in the WPF Window.

                       

                      1 of 1 people found this helpful
                        • Re: AFDatabasePicker
                          gregor

                          Hi Eugene,

                           

                          I wasn't aware that it is possible to use Windows Forms Controls inside XAML. Thank you for teaching me differently.

                           

                          The only thing that I was struggling with a little, was to find the proper using clause for the Forms integration because it was not obvious to me based on the assembly name (WindowsFormsIntegration):

                           

                          using System.Windows.Forms.Integration;