开发者

Writing a WPF WinForms Control wrapper

I am using a w开发者_C百科in 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜