locked
Is it possible to add a WPF component/code in a NET Core 3.1 Windows Form Application RRS feed

  • Question

  • Hello!

    I have a question about .NET Core 3.1 Windows Form Application.

    I am currently developing such application and now I do have a third party component which is a special chart that only is compatible with WPF where this chart is a XAML component.

    Is there a way to use this component in a  .NET Core 3.1 Windows Form Application in any way.

    With that I beleive I mean if there is a way to create this XAML component in a separate file which has its own C# code behind also which interacts with that XAML GUI component (which is important).

    Then be able to gain access to those variables/memory from that chart, - from the C# code in the .NET Core 3.1 Windows Form Application which is the main application?

    Thank you!




    • Edited by Silvers11 Friday, May 1, 2020 5:18 PM
    Friday, May 1, 2020 4:16 PM

Answers

  • .NET Core is still evolving which is why it doesn't work in .NET Core and does in .NET Framework. So right now it's not possible.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Silvers11 Saturday, May 2, 2020 2:19 PM
    Friday, May 1, 2020 11:33 PM

All replies

  • In Winforms and .NET Framework, I use ElementHost

    and  for .NET Core, the doc says :

    ".NET Core

    3.1, 3.0"

    There are tutorials like  :

    Walkthrough: Hosting a WPF Composite Control in Windows Forms


    • Edited by Castorix31 Friday, May 1, 2020 5:26 PM
    Friday, May 1, 2020 5:25 PM
  • Thank you, I am trying to implement that example from that link.

    I have managed to put all code in place now but get an error for the below lines. 

    The error points to: "InitializeComponent()"

    Reference to type DependencyObject claims it is defined in WindowsBase but it could not be found

    I have created:

    WPF User Control Library .NET Core 3.1

    Windows Form Application .NET Core 3.1

    So the below "wpfAddressCtrl" is the WPF control that I try to Initialize in the Form Application?

    wpfAddressCtrl = new MyControls.MyControl1();
    wpfAddressCtrl.InitializeComponent();


    • Edited by Silvers11 Friday, May 1, 2020 9:16 PM
    Friday, May 1, 2020 8:58 PM
  • Hello,

    Sorry to say but it's unlikely this is possible at this time as Microsoft with this is a work in progress. You might want to read the following and leave feedback to what you are after. Note any time it's got preview it's most likely going to change in the future so don't get attached to the current code base.

    https://devblogs.microsoft.com/dotnet/updates-to-net-core-windows-forms-designer-in-visual-studio-16-5-preview-1/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, May 1, 2020 9:42 PM
  • Karen,

    Thank you. I red the link. So it could be that .NET Core hasn't implemented this functionality yet probably.

    I tried something else now. Instead of using .NET Core 3.1 which is what I initially need as I develop in this. I tried the same creating those 2 projects instead with the  .NET FrameWork and now it worked perfectly.

    Could there be any problem with the .NET Core 3.1 Form Application that can't initiliaze the WFP component?

    If that is a problem. Could there be any other idéa of how to gain access to the WPF component and its variables in that project from the .NET Core 3.1 Form application?

    WPF User Control Library  .NET FrameWork

    Windows Form Application .NET FrameWork



    • Edited by Silvers11 Friday, May 1, 2020 10:12 PM
    Friday, May 1, 2020 9:54 PM
  • .NET Core is still evolving which is why it doesn't work in .NET Core and does in .NET Framework. So right now it's not possible.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Silvers11 Saturday, May 2, 2020 2:19 PM
    Friday, May 1, 2020 11:33 PM
  • Yes then I understand. I wrote a comment/feedback as you said about it also on the link you posted.

    Thank you Karen for your help!

    Saturday, May 2, 2020 2:21 PM