wpfxamlwindowsformshost

impossible to bind my model with the Text of a forms: DomainUpDown


for some day now, I have been desperately looking for a way to link a property (string in this case) of my model, to the Text property of a DomainUpDown contained in a . But every time I try I get the message: object of type 'system.windows.data.binding' cannot be converted to type 'system.string'

here is the xaml code :

    <Window.Resources>
 <local: Timer x: Key = "Timer" />
</Window.Resources>
<Grid>
 <WindowsFormsHost>
 <formsomainUpDown x: Name = "ModeDomainUpDown" Text = "{Binding Source = {StaticResource Timer}, Path = Mode, Mode = TwoWay}" />
</WindowsFormsHost>

I specify that my model is here the Timer class whose property to binder is Mode (a String) Mode is initialized to "IN" in my default constructor

Timer is not just a simple POCO but is observable via the INotifyPropertyChanged interface moreover being a little long I will not detail it here

thank you in advance for your help


Solution

  • If formsomainUpDown is a winforms control, and its 'Text' property is not a DependencyProperty(which is likely), then you cannot bind its value to anything.

    To use binding in WPF requires your controls property to be a DependencyProperty.

    You should wrap the control and its host in another UserControl, and make a DependencyProperty on it, and in code listen to changes of Text property and commit the changes to the new DependencyProperty.