|
|
|
I'm trying to check to see if a WCF service is running, and if not, exit. So far I have this:
bool serviceRunning = true;
try
{
Proxy = new MyAppServiceRef.MyAppServiceClient();
}
catch (Exception e)
{
serviceRunning = false;
}
try
{
serviceRunning = !Proxy.ServiceRunning();
}
catch (Exception e)
{
serviceRunning = false;
}
if (!serviceRunning)
{
string message = "The service appears to not be running. Please check the service. " + ApplicationTitle + " will now exit.";
MessageBox.Show(message, "Service Error", MessageBoxButton.OK, MessageBoxImage.Stop);
Application.Current.Shutdown();
}
1) is this really the way to do this?
2) After the call to Application.Current.Shutdown() the app continue to run and I get XAML errors. How to I actually stop the app dead right here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
hello
I say first that this code works with windowsFormApplication, but no work with wpf, help me please
namespace WpfApplication22
{
public partial class App : Application
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
private const int APPCOMMAND_XXX = 0x80000;
private void MetodoMute(object sender, EventArgs e)
{
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
(IntPtr)APPCOMMAND_xxx);
}
}
}
when I use:
private void button4_Click(object sender, RoutedEventArgs e)
{
App x = new App();
x.MetodoMute(new WindowInteropHelper(this).Handle);
}
not works, It's launch exception:
"Eccezione non gestita di tipo 'System.InvalidOperationException' in PresentationFramework.dll
Informazioni aggiuntive: Impossibile creare più di un'istanza System.Windows.Application nello stesso AppDomain."
how do I call a method written in App.xaml.cs from another window?
|
|
|
|
|
App is a special class - it's the entry point for your WPF application. In other words, it's the class you use to create your application - the good news is that this class is available throughout the code base, so all you need to do is use App.MetadoMute (also, you need to use a method call that matches your signature).
|
|
|
|
|
I can not use App.MyMetod(...) in the file MainWindow.xaml.cs
don't work
how do I call a method written in the class App from the class MainWindow?
private void button4_Click(object sender, RoutedEventArgs e)
{
App.MetodoMute(new WindowInteropHelper(this).Handle);
}
|
|
|
|
|
You can use Application as your class to call MetodoMute. You simply cast it to App.
|
|
|
|
|
New here. I hope I don't get lambasted for asking this here and being a little long winded. I have a twenty some year career as a programmer(RPGLE)IBM. About a year ago I took a few classes on c# and then was taught a little about WPF. And was able to add some controls and stuff to some existing apps in our shop. Loved it. Then I found out we weren't exactly doing WPF the correct way. I want to change and go into .net full time. My problem is.. Everybody has a different opinion on what is the right way to do it. I am currently going through Pro WPF in C# by Matthew McDonald. I REALLY want to learn this and be able to find a job doing this. In my old world of programming, I learned the basics and really took off. Once I got a good shell of a program and or screen I used that to reuse code, expand into more complex applications and continue to learn from repetition. I feel like if I can get a good example of a correct WPF application I can easily catch on like I did in my old career. I learn by repetition. And getting examples of hello world and junk isn't what I'm looking for. I need to learn real world techniques... I am interested in business apps with database(SQL) behind. Binding and such. Am I way off base here ? Please share your thoughts, it will be much appreciated. I will not be this long winded again. Thanks!
|
|
|
|
|
Go to the Articles section here on CodeProject[^] and you will find lots of great articles that will teach you all you need to know.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Ya, thanks. I've been doing that all over the net. I create something and then people say its wrong... Painful. I guess I'm looking for a little clearer direction.
|
|
|
|
|
ljv_az wrote: I guess I'm looking for a little clearer direction. That's a little more than can be provided in a technical forum. You need to study the subjects of interest using books, online articles, as I already suggested, and maybe even a course of some kind.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Ok. I don't mean to be an ahole but did you read my original post? I have started developing a few WPF applications. I HAVE read books and taken some direction from videos and from other so called ".net developers". What I'm looking for is some clearer direction on how to get a good start the "right" way to develop WPF apps. Example... I see people using coordinates and sizes to layout their WPF window. Then I was told that is wrong. Only used mins and max's and padding. I use Visual Studio when designing my window or form. I was told that is garbage and I should hand key in the XAML for things like my grid rows and columns. On and on... So I was looking for an example of a small app that was done correctly and I could look at it and see how its done and use that as a good start for doing more complex apps the way WPF was inteneded to be used. I just find it a bit frustrating when you come across an example of a WPF app and then you start reading all the responses to the posting of that app and other people say it's wrong.
|
|
|
|
|
ljv_az wrote: What I'm looking for is some clearer direction And that's what I directed you towards: the CodeProject contains lots of great articles, many specific to WPF. If you are expecting a full tutorial on the 'proper' way to write WPF applications then I'm afraid you misunderstand the purpose of these forums, and should read again How to get an answer to your question[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'm done with the discussion. I didn't asked for a tutorial. Your being an idiot. I was asking for clarification and pointed out specific points of needed clarification but you just want to be an ahole. I'll gladly go somewhere else. I've been in the programming business for over twenty years I'm not stupid. I was simply looking for some clarification. There are alot of good people with alot of good help on discussion boards but there is always some wise ass. Thanks.
|
|
|
|
|
Well I think people can judge who is what here. I have tried to explain how this forum works, I have pointed you to articles that will give you lots of clarification of the issues you may be looking for (none of which you gave details of), and I refrained from insulting you.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I don't care what people think. I'm not interested in a popularity contest. You say I never gave you details... This is why I made the comment you don't read all of my response... I said, and you can look back...
" I see people using coordinates and sizes to layout their WPF window. Then I was told that is wrong. Only used mins and max's and padding. I use Visual Studio when designing my window or form. I was told that is garbage and I should hand key in the XAML for things like my grid rows and columns. On and on... So I was looking for an example of a small app that was done correctly and I could look at it and see how its done and use that as a good start for doing more complex apps the way WPF was inteneded to be used. " That would be details.....
I'm not going to go back and forth its not productive. And you are right, I don't need to insult anyone. I will go elsewhere.
|
|
|
|
|
ljv_az wrote: I was told that is wrong.
ljv_az wrote: I was told that is garbage
Told by whom, and why is their opinion the correct one?
ljv_az wrote: So I was looking for an example
And I told you where to find plenty, I did not give you a link to the specific one that you wanted because I don't have time to go and search for the exact application that you are demanding. Unfortunately, like too many people who make no contribution to this site, you seem to believe that you have the right to make any demands that you want here, and it's our responsibility to provide what you are demanding, despite the fact that it is costing you nothing.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You are something... I never demanded anything. People go to forums for help, advice and examples. I have many times and still do give code examples for my old platform. I actually enjoy helping people. I don't play games and berate them. I found a few other sites and was gladly given some solid examples by decent people. I will delete my account here. You my friend are a piece of work.... Good bye!!
|
|
|
|
|
ljv_az wrote: I never demanded anything. On the contrary, you have repeatedly abused me for not providing what you are asking for, despite the fact that I told you where you could find it. As I said before, you are like so many people these days, if you don't get exactly what you ask for then you revert to type and become abusive.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
No, I went somewhere else and got what I was looking for from someone who's not an idiot. You are hilarious! You seem to have trouble with alot of people.
|
|
|
|
|
ljv_az wrote: You seem to have trouble with alot of people. No, just the ones who are too stupid or lazy to do anything for themselves.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Ahh, the perennial problem of what makes a good WPF application. Most of the time, the reasoning that you will be given will be parroted without actually understanding what and why it's really so.
In any case, most of the time what people are referring to is using MVVM. I would suggest that you search for the MSDN article on MVVM by Josh Smith. You might, also, look at one of the popular MVVM frameworks such as Cinch by Sacha Barber which has lots of documentation here on Code Project.
Unfortunately I am typing this on my phone so I can't give you direct links. They are easy to find though.
|
|
|
|
|
Try using Expression Blend, I used it to get me started with WPF and it helped me alot.
|
|
|
|
|
MVVM seems to be the appropriate style everyone can agree upon for WPF. My problem is with certain third party controls you can't use MVVM. I use Actipro Software's WPF ribbon for example and it doesn't support MVVM. Another issue I've had with MVVM is using Treeview controls and responding to the node selected. While there are way to do it in MVVM it seems way more difficult then simply using Visual Studio to create the events. The whole purpose is to separate the code from the XAML by using binding. While I do practice this for the most part sometimes you just can't justify writing something that has a learning curve which increases the projects time to complete by two fold. It boils down in my opinion to what ever method works best for you and the company you work for. I have a much better understanding of MVVM now than I had but it doesn't help to try to learn a new style of programming using controls that aren't designed to work with that style.
|
|
|
|
|
Ahh, the halcyon days of RPGLE - how I miss them (not!)
ljv_az wrote: Everybody has a different opinion on what is the right way to do it.
There's the clue to your dilemma; there is no 'right' way of doing WPF. You might decide to use MVVM or you might not - doesn't make it 'wrong'. In RPG you might use an 'if' or you might use one of those 'two-digits in a column that act like an if' things (it's been a while!) neither is 'wrong' it's often down to personal preference. (I had a manager who insisted on using the logic cycle in programs - but his reasons were, essentially, because that's what he was used to, coming from an RPG II background)
My rule of thumb is to listen to the REASONS people give for doing things one way (or not doing them that way) and make your own mind up.
Someone saying 'you shouldn't put any code in the code-behind' for example, is less than useless without the addition of a 'because...' If you listen to the 'because' bit you can then make up your own mind whether that's the 'right' way or not, and formulate your own rules; then next time someone criticises your code, you can respond with reasoned argument.
I've
|
|
|
|