简体   繁体   中英

Writing a WPF WinForms Control wrapper

I am using a win forms control library for which I do not have the source code.

My app is c# WPF/XAML, etc. So, I am writing wrappers for the WinForms controls. Other than a few minor inconvenient issues this is all going quite well. Until...

I have two Winforms Forms controls

public class WFC_A
{
}

public class WFC_B
{
    public WFC_A WFC_A_Property { get; set; }
}

and two WPF controls

public class WPF_A
{
     private WFC_A wfca;
}

public class WPF_B
{
     private WFC_B wfcb;
     public static readonly DependencyProperty WPF_A_Property =
            DependencyProperty.Register("WPF_A_Property", typeof(WPF_A),
            typeof(WPF_B), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnWPFAPropertyChanged)));

}

...

The problem is when the Dependency Property changes I want to take a reference to the WFC_A and save it as

wfcb.WFC_A_Property = WPF_A.wfca

1) It seems a really good case for c++ friend class but this is not available in c#. 2) These are both quite large wrapper classes and I really prefer not to nest them. 3) I could make the inner wfc properties public but I am trying to abstract all the Winforms stuff away so it can be replaced with another library later.

Any suggestions for the right way to achieve what I'm trying to do?

Thanks.

The best thing I can think of is to make the property internal. If your wrappers are in a library that is used by an application, they won't have any clue you did that. If the wrappers are in the same assembly as your application, that might not be so clean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM