Open fo40225 opened 2 years ago
@RussKie The implementation of the converter is in winforms, could you please look at this issue once?
The TextBox.AutoCompleteSource
has a TextBoxAutoCompleteSourceConverter
converter applied. However, the converter does not have parameterless constructor, and therefore is unusable in XAML.
The TextBoxAutoCompleteSourceConverter
actually derives from EnumConverter
which itself does not have parameterless constructor. The XamlValueConverter
which is in charge of creating the converter has a special case for converters of type EnumConverter
, however, it does not support converters derived from it. WinForms has couple of such converters, although the others are much less likely to appear in XAML.
One solution is to ignore custom value converters on enum properties and always create an instance of EnumConverter
for them (i.e. relax the converter type check from == to inherits from). Another one is to contractually expect any type converter deriving from EnumConverter
to have a constructor that expects one Type
parameter. Both these solutions would break any well designed existing enum converters that have parameterless constructors.
The cleanest fix is probably on WinForms side, to provide a parameterless constructor for this converter. Most of the converters were designed for one particular enum, so it should be possible to call the base constructor with that enum type.
(Also note that I couldn't find any documentation on type converters stating the parameterless constructor requirement for use in XAML.)
I'm not sure what kind of help you're expecting. You're trying to use Windows Forms types in WPF scenarios, and this has never been officially supported.
The cleanest fix is probably on WinForms side, to provide a parameterless constructor for this converter. Most of the converters were designed for one particular enum, so it should be possible to call the base constructor with that enum type.
I'm not convinced this is true. The right way would be for WPF to provide the necessary converter and decorations on the TextBox control.
You're trying to use Windows Forms types in WPF scenarios, and this has never been officially supported.
The existence of WindowsFormsHost and documentation like https://docs.microsoft.com/en-us/dotnet/desktop/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf-by-using-xaml suggests otherwise. Perhaps you are suggesting WinForms have not agreed to this contract and as such it is up to WPF to fix any incompatibilities?
My suggestion of adding parameterless constructor to the converter(s) is a trivial solution that has zero performance impact on both WPF and WinForms side. If that is not an option on WinForms side and WPF is willing to take either performance hit on supporting this case or dependence on this particular WinForms type, then there are other ways to fix this.
I don't see how WPF can provide decorations on WinForms' TextBox control, can you elaborate? What the user can do to workaround the problem is either derive a custom control from TextBox and get rid of the type converter, or do not use XAML to set this property.
dotnet --info
)winver
)Security issues and bugs should be reported privately, learn more via our responsible disclosure guidelines.
Problem description: System.Windows.Markup.XamlParseException: 'Constructor on type 'System.Windows.Forms.TextBoxAutoCompleteSourceConverter' not found.' Actual behavior:
內部例外狀況 1: MissingMethodException: Constructor on type 'System.Windows.Forms.TextBoxAutoCompleteSourceConverter' not found.