Embedding WPF Control into IComPropertySheet

1880
4
07-07-2011 06:48 AM
ThavitinaiduGulivindala
Occasional Contributor
Hi,

I have seen samples that embed classes (implementing System.Windows.Forms.UserControl, IComPropertyPage) into IComPropertySheets. Can we user WPF UserControl instead of Windows Forms Control to embed into IComPropertySheet.
0 Kudos
4 Replies
AlexanderGray
Occasional Contributor III
I had asked ESRI what their stance was in supporting WPF in ArcGIS at the UC last year, they told me it was supported using a windows forms WPF container control.  So you would still need a windows custom control that would have a WPF container control on it.  Not sure how that is going to work in a property page.  It should work but I would be cautious with event handling, specifically key press events.   I not sure how well the events pass through ArcMap to windows forms to WPF. 

Alternatively you might be able to create a custom control by inheriting from the WPF container control and implementing the IComPropertyPage interface on it and put the COM visible attributes and the registration stuff too.
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
Hi Gray,

Thanks for your reply.
I have started implementing but have problem with Key events as you have montioned. To be specific, I have a listbox with items added to it. I have selected an item in the listbox and pressed Down/Up key. I expect that Next/Previous item to selected in the listbox. But the focus is moving to the parent Tab (Property Page) though the currenly selected item is in the middle. Neither Tab key works to navigate between the WPF controls in the Property Page.
I have checked the 2nd approach mentioned in ur ealrier post but no improvement.

Any suggestion to overcome this.

Thanks in advance.
0 Kudos
AlexanderGray
Occasional Contributor III
Yes the whole keyboard events in controls is a bit of a mess.  I get that problem with a windows control too. 

I did something like this in the windows control.  Basically create my own handlers.  I don't have list boxes but I think that is just the up and down keys.

 Public Sub Initialize()
       WorkaroundTabIndexDefect()
 End Sub

''' <summary>
  ''' Works around the tab index defect.
  ''' </summary>
  Private Sub WorkaroundTabIndexDefect()
    For Each ctr As Control In Me.Controls
     
      SetKeyDownHandlers(ctr)

    Next


  End Sub

  ''' <summary>
  ''' Sets the key down handlers.
  ''' </summary>
  ''' <param name="ctr">The CTR.</param>
  Private Sub SetKeyDownHandlers(ByVal ctr As Control)
    Dim txtCtr As TextBox = TryCast(ctr, TextBox)
    If txtCtr IsNot Nothing Then
      txtCtr.AcceptsTab = True
      txtCtr.AcceptsReturn = True
      Dim evh As KeyEventHandler = New KeyEventHandler(AddressOf WorkaroundKeyDown)
      AddHandler txtCtr.KeyDown, evh
    Else
      ctr.TabStop = False
    End If

    If ctr.Controls.Count > 0 Then
      For Each subCtr As Control In ctr.Controls
        SetKeyDownHandlers(subCtr)
      Next

    End If

  End Sub

 
  ''' <summary>
  ''' Workarounds the key down.
  ''' </summary>
  ''' <param name="sender">The sender.</param>
  ''' <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs" /> instance containing the event data.</param>
  Private Sub WorkaroundKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    Try
      If Me.ActiveControl IsNot Nothing Then
        Select Case e.KeyCode
          Case Keys.Return
            Dim btnCtr As Windows.Forms.Button = TryCast(Me.ActiveControl, Windows.Forms.Button)
            If btnCtr IsNot Nothing Then
              btnCtr.PerformClick()
            End If
          Case Keys.Tab
            If e.Shift Then
              Me.SelectNextControl(CType(sender, Control), False, True, True, True)
            Else
              Me.SelectNextControl(CType(sender, Control), True, True, True, True)
            End If



        End Select
      End If
    Catch ex As Exception
      Trace.WriteLine(ex)
    End Try
  End Sub
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
Hi Gray,

Thanks for your reply again.
Let me try ur approach. But I doubt whether i can embed the default behaviour of the WPF Controls. e.g. If the Control is Listbox and Down key is pressed, will the next item get selected by default or I need to write code for that too.
0 Kudos