How to share methods between multiple wpf apps with a library
I have half a dozen separate wpf apps which run simultaneously. However, they have a lot of overlapping code, eg in connecting to a database and sending notifications. I would like to be able to write these methods once and have all the wpf apps be able to use the same definitions. If there are changes to these shared methods I want to be able to update them together.
I have tried setting up a .Net standard class library, but then I can't use "using System.Data.Odbc" which I need for my methods. I've also tried the WPF user control library and the WPF custom control library but when I try and call the methods I get the error "The name XXX does not exist in the current context." I have added a reference to the library but it's not helping.
What is the best way to have shared methods? Am I on the right track with the libraries?
// USER CONTROL
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
// MY CODE HERE - HAVE TRIED SEVERAL TESTS
public static class mytest
{
public static string Mytest()
{
return "Test123";
}
public static string Mytest2(this String str)
{
return "Test123";
}
}
}
// EXAMPLE XAML.CS FOR APP. HAVE TRIED TO CALL MYTEST AND MYTEST2 BUT THEY DON'T EXIST
namespace MY_Logic
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Mytest();
string testword = "test";
testword.Mytest2();
}
}
}
wpf dll
add a comment |
I have half a dozen separate wpf apps which run simultaneously. However, they have a lot of overlapping code, eg in connecting to a database and sending notifications. I would like to be able to write these methods once and have all the wpf apps be able to use the same definitions. If there are changes to these shared methods I want to be able to update them together.
I have tried setting up a .Net standard class library, but then I can't use "using System.Data.Odbc" which I need for my methods. I've also tried the WPF user control library and the WPF custom control library but when I try and call the methods I get the error "The name XXX does not exist in the current context." I have added a reference to the library but it's not helping.
What is the best way to have shared methods? Am I on the right track with the libraries?
// USER CONTROL
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
// MY CODE HERE - HAVE TRIED SEVERAL TESTS
public static class mytest
{
public static string Mytest()
{
return "Test123";
}
public static string Mytest2(this String str)
{
return "Test123";
}
}
}
// EXAMPLE XAML.CS FOR APP. HAVE TRIED TO CALL MYTEST AND MYTEST2 BUT THEY DON'T EXIST
namespace MY_Logic
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Mytest();
string testword = "test";
testword.Mytest2();
}
}
}
wpf dll
You just use a normal .Net library. Then you add a reference to the library and the using statement.
– SledgeHammer
Jan 2 at 0:56
@SledgeHammer if I use a .NET Standard class library, when I add my using System.Data.Odbc statement I get the error "The type or namespace Odbc does not exist in the namespace System.Data (are you missing an assembly reference?)
– Confused
Jan 2 at 2:18
I said .Net, not .Net Standard. The system.data references should already be there.
– SledgeHammer
Jan 2 at 2:48
In Visual Studio when I go to add a .net library I can see .NET core, .NET Standard and .NET framework. I've now switched to .NET framework and it's working! Thanks for your help :)
– Confused
Jan 2 at 3:00
add a comment |
I have half a dozen separate wpf apps which run simultaneously. However, they have a lot of overlapping code, eg in connecting to a database and sending notifications. I would like to be able to write these methods once and have all the wpf apps be able to use the same definitions. If there are changes to these shared methods I want to be able to update them together.
I have tried setting up a .Net standard class library, but then I can't use "using System.Data.Odbc" which I need for my methods. I've also tried the WPF user control library and the WPF custom control library but when I try and call the methods I get the error "The name XXX does not exist in the current context." I have added a reference to the library but it's not helping.
What is the best way to have shared methods? Am I on the right track with the libraries?
// USER CONTROL
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
// MY CODE HERE - HAVE TRIED SEVERAL TESTS
public static class mytest
{
public static string Mytest()
{
return "Test123";
}
public static string Mytest2(this String str)
{
return "Test123";
}
}
}
// EXAMPLE XAML.CS FOR APP. HAVE TRIED TO CALL MYTEST AND MYTEST2 BUT THEY DON'T EXIST
namespace MY_Logic
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Mytest();
string testword = "test";
testword.Mytest2();
}
}
}
wpf dll
I have half a dozen separate wpf apps which run simultaneously. However, they have a lot of overlapping code, eg in connecting to a database and sending notifications. I would like to be able to write these methods once and have all the wpf apps be able to use the same definitions. If there are changes to these shared methods I want to be able to update them together.
I have tried setting up a .Net standard class library, but then I can't use "using System.Data.Odbc" which I need for my methods. I've also tried the WPF user control library and the WPF custom control library but when I try and call the methods I get the error "The name XXX does not exist in the current context." I have added a reference to the library but it's not helping.
What is the best way to have shared methods? Am I on the right track with the libraries?
// USER CONTROL
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
}
// MY CODE HERE - HAVE TRIED SEVERAL TESTS
public static class mytest
{
public static string Mytest()
{
return "Test123";
}
public static string Mytest2(this String str)
{
return "Test123";
}
}
}
// EXAMPLE XAML.CS FOR APP. HAVE TRIED TO CALL MYTEST AND MYTEST2 BUT THEY DON'T EXIST
namespace MY_Logic
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Mytest();
string testword = "test";
testword.Mytest2();
}
}
}
wpf dll
wpf dll
asked Jan 2 at 0:39
ConfusedConfused
41
41
You just use a normal .Net library. Then you add a reference to the library and the using statement.
– SledgeHammer
Jan 2 at 0:56
@SledgeHammer if I use a .NET Standard class library, when I add my using System.Data.Odbc statement I get the error "The type or namespace Odbc does not exist in the namespace System.Data (are you missing an assembly reference?)
– Confused
Jan 2 at 2:18
I said .Net, not .Net Standard. The system.data references should already be there.
– SledgeHammer
Jan 2 at 2:48
In Visual Studio when I go to add a .net library I can see .NET core, .NET Standard and .NET framework. I've now switched to .NET framework and it's working! Thanks for your help :)
– Confused
Jan 2 at 3:00
add a comment |
You just use a normal .Net library. Then you add a reference to the library and the using statement.
– SledgeHammer
Jan 2 at 0:56
@SledgeHammer if I use a .NET Standard class library, when I add my using System.Data.Odbc statement I get the error "The type or namespace Odbc does not exist in the namespace System.Data (are you missing an assembly reference?)
– Confused
Jan 2 at 2:18
I said .Net, not .Net Standard. The system.data references should already be there.
– SledgeHammer
Jan 2 at 2:48
In Visual Studio when I go to add a .net library I can see .NET core, .NET Standard and .NET framework. I've now switched to .NET framework and it's working! Thanks for your help :)
– Confused
Jan 2 at 3:00
You just use a normal .Net library. Then you add a reference to the library and the using statement.
– SledgeHammer
Jan 2 at 0:56
You just use a normal .Net library. Then you add a reference to the library and the using statement.
– SledgeHammer
Jan 2 at 0:56
@SledgeHammer if I use a .NET Standard class library, when I add my using System.Data.Odbc statement I get the error "The type or namespace Odbc does not exist in the namespace System.Data (are you missing an assembly reference?)
– Confused
Jan 2 at 2:18
@SledgeHammer if I use a .NET Standard class library, when I add my using System.Data.Odbc statement I get the error "The type or namespace Odbc does not exist in the namespace System.Data (are you missing an assembly reference?)
– Confused
Jan 2 at 2:18
I said .Net, not .Net Standard. The system.data references should already be there.
– SledgeHammer
Jan 2 at 2:48
I said .Net, not .Net Standard. The system.data references should already be there.
– SledgeHammer
Jan 2 at 2:48
In Visual Studio when I go to add a .net library I can see .NET core, .NET Standard and .NET framework. I've now switched to .NET framework and it's working! Thanks for your help :)
– Confused
Jan 2 at 3:00
In Visual Studio when I go to add a .net library I can see .NET core, .NET Standard and .NET framework. I've now switched to .NET framework and it's working! Thanks for your help :)
– Confused
Jan 2 at 3:00
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000065%2fhow-to-share-methods-between-multiple-wpf-apps-with-a-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000065%2fhow-to-share-methods-between-multiple-wpf-apps-with-a-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You just use a normal .Net library. Then you add a reference to the library and the using statement.
– SledgeHammer
Jan 2 at 0:56
@SledgeHammer if I use a .NET Standard class library, when I add my using System.Data.Odbc statement I get the error "The type or namespace Odbc does not exist in the namespace System.Data (are you missing an assembly reference?)
– Confused
Jan 2 at 2:18
I said .Net, not .Net Standard. The system.data references should already be there.
– SledgeHammer
Jan 2 at 2:48
In Visual Studio when I go to add a .net library I can see .NET core, .NET Standard and .NET framework. I've now switched to .NET framework and it's working! Thanks for your help :)
– Confused
Jan 2 at 3:00