0

I want to have auto-completion on my multi-line TextBox. Sadly, it seems that WPF does not support this, and the classes from other people I have looked at did not meet my requirements. I found that hosting Windows Forms components is possible in WPF, but I do not understand how to properly "translate" my WPF TextBox:

<TextBox Text="{Binding MyViewModel.MyText}" Style="{StaticResource EventTextBox}" Background="{Binding MyViewModel.MyTextBackgroundColor}">
    <ie:Interaction.Triggers>
        <ie:EventTrigger EventName="LostFocus">
             <mvvml:EventToCommand Command="{Binding MyViewModel.MyTextLostFocusCommand}" PassEventArgsToCommand="True" />
        </ie:EventTrigger>
        <ie:EventTrigger EventName="GotFocus">
            <mvvml:EventToCommand Command="{Binding MyViewModel.MyTextHasFocusCommand}" PassEventArgsToCommand="True"/>
        </ie:EventTrigger>
    </ie:Interaction.Triggers>
</TextBox>

where we use

xmlns:ie="http://schemas.microsoft.com/expression/2010/interactivity"

and

xmlns:mvvml="http://www.galasoft.ch/mvvmlight"

for signaling.

My Windows Forms Textbox:

<WindowsFormsHost>
    <wf:TextBox x:Name="myFormsTextBox"/>
</WindowsFormsHost>

Side questions: How do I translate Style="" and Background="" to Windows Forms, as well as the EventToCommand events?

Main question: How do I do Two-Way data binding for MyViewModel.MyText <=> Windows Forms Textbox?

I looked at https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf-by-using-xaml and https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-binding-to-data-in-hybrid-applications but am none the wiser.

Harsha J K
  • 197
  • 1
  • 1
  • 17
ThE_-_BliZZarD
  • 722
  • 2
  • 12
  • 26
  • My best suggestion to you: please avoid at all costs the WinForms integration in WPF. The focus handling between these two worlds is just a pain. There are another side-effects you *will* encounter, especially if the WinForms control's author did use some Windows messages tricks etc. – dymanoid Apr 04 '18 at 13:25
  • Did you read this? https://stackoverflow.com/questions/38529025/binding-windowsformshost-child-property – mm8 Apr 04 '18 at 14:27

0 Answers0