How do I rewrite the WPF code to WinForm C# .NET

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 2787 Views - Last Post: 16 August 2016 - 07:22 PM Rate Topic: -----

#1 DOT1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 02-November 14

How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 08:56 AM

I am working on a small project where I want to connect a application with my WiFi lightbulb.
I already have the source files for the original Windows application but its made with WPF.
I would like to make it into a WinForm application because it makes things alot easier to build and develop since im not too good with WPF.

The issue is that even though I have the source code infront of me,
its very confusing. I thought it would be just copy/pasting it
but it turns out that it wasnt that simple since I needed refrences that I couldnt find online and things were hooked up to special WPF things that I couldnt solve.

As you can see in the GitHub link below, everything is there.
https://github.com/d...mpleApp.Windows

1. It find the connected lightbulb
2. Its able to turn it on and off.

For some reason it was really hard to find which did which and how to convert it into a WinForm state and not a WPF.

What I need help with exactly is.

1. rewrite the method from WPF to WinForm(Doesnt want to seem to work when Id o it, I would show errors but it creates 50 errors)
2. I only need to rewrite the code that finds the lightbulb and selects it and then use a button as a switch.

This post has been edited by DOT1: 12 August 2016 - 08:57 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How do I rewrite the WPF code to WinForm C# .NET

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 09:02 AM

What is your question, or is this a less than subtle "do the conversion for me"?

Do you have errors? If so copy/paste them here with relevant code.

Not to mention it seems their help bit and looking where 'LifxNet.LifxClient' is used cuts through the WPF pretty succinctly.
Was This Post Helpful? 1
  • +
  • -

#3 DOT1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 02-November 14

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 09:06 AM

Im sorry i should of been more clear! Its just that I've been at this for 2 days now and its bugging the crap out of me that I cant find a solution or any good docs.

I guess my first question is..

How do I make find the connected lightbulbs? I can see that its these lines of code
		ObservableCollection<LifxNet.LightBulb> bulbs = new ObservableCollection<LifxNet.LightBulb>();
		LifxNet.LifxClient client = null;


but to behonest I have no idea what to do after that. Do I create a listbox and add the "bulbs" there?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 09:17 AM

Okay.. so you follow those variables in the WPF.. see how they are used and mimic it. It's not like there is a ton of crazy code in there.. Things are laid out extremely well.

Plus - there's always the documentation:
https://community.li...oping-with-lifx
https://api.develope...cs/toggle-power
https://github.com/L...x-protocol-docs
Was This Post Helpful? 1
  • +
  • -

#5 DOT1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 02-November 14

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 09:28 AM

Im really looking up to programmers löike yourself, I've been programming for a few months now and my goal is to be able to do stuff like this without having to ask for help by the end of 2016 so thank you for the help! :D

Now.. So what I tried doing right now is to create a variable in amethod that I created called findBulbs
but it throws me this error(and yes I already added the dll)

The type or namespace name 'LifxNet' could not be found (are you missing a using directive or an assembly reference?)
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15329
  • View blog
  • Posts: 61,444
  • Joined: 12-June 08

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 09:37 AM

Did you add a reference to the project for the DLL? Sounds like you did not.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 10:10 AM

:withstupid:

Quote

I would like to make it into a WinForm application because it makes things alot easier to build and develop since im not too good with WPF.

Then push your skills up to this decade, rather than try to cripple good modern code by reverting back 15+ years.
Taking WPF and trying to roll it back to WinForms is like taking a 2016 Dodge Ram Limited and asking how you can reverse it back to a 1965 Ford F150.
Was This Post Helpful? 2
  • +
  • -

#8 DOT1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 02-November 14

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 10:13 AM

View PosttlhIn`toq, on 12 August 2016 - 10:10 AM, said:

:withstupid:/>

Quote

I would like to make it into a WinForm application because it makes things alot easier to build and develop since im not too good with WPF.

Then push your skills up to this decade, rather than try to cripple good modern code by reverting back 15+ years.


So you are saying that WinForm is useless? That I should move over to WPF instead?
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 10:15 AM

YES

Look at the second link in my signature that reads "WHY YOU SHOULD STOP USING LONG DEAD WINFORMS"
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 10:18 AM

No programming technology is "useless". But it's old, out of date, and not being updated anymore (and it hasn't been in over a decade). WPF isn't really the "new thing" anymore (it's been around for many years), and is being supplanted by UWP applications (which are extremely similar to WPF, they use XAML and the MVVM pattern heavily).

So it's more of a "do you want to be stuck using Windows Forms for everything, writing applications that look like they were designed 10+ years ago, or do you want to be working on a modern platform, with modern patterns, that will give you experience on something that is current, not outdated.

It's like learning how to use Lotus 1-2-3 instead of Excel. It's not that one is useless, it's just that you're going to get more mileage out of Excel in the long run.

And if you're starting from a position of learning, why not learn the modern thing instead of the out of date thing?

And "it's hard" or "I'm not good at WPF" isn't a good excuse when you're a programmer. Don't be the lazy programmer that searches for the easy and hack-ish ways out. Be the kind that tackles challenges head-on and learns new technologies when necessary.
Was This Post Helpful? 2
  • +
  • -

#11 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 10:22 AM

Quote

and is being supplanted by UWP applications (which are extremely similar to WPF, they use XAML and the MVVM pattern heavily).

UWP has been around too and never really taken hold. I'd go so far as to say that Xamarin is going to keep taking traction fast now that Microsoft bought it. Its just a different implimenation of the XAML language: So its WPF-adjacent... But lets the same code run on UWP *AND* iOS *AND* Android. So if you're going to make an app for UWP why wouldn't add 10% more work on the front end to be totally cross platform?
Was This Post Helpful? 0
  • +
  • -

#12 DOT1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 02-November 14

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 10:22 AM

Good point! Curtis.. Its a shame that it makes me feel like I did C# for 6 months for no reason what so ever except to come to a sign that says "What you just learned doest even matter time to start over"
But I'l guess I start picking up on WPF.
Was This Post Helpful? 0
  • +
  • -

#13 Curtis Rutland   User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 11:13 AM

@tlhIn`toq truth is, I spend almost 100% of my time writing web-based applications these days. I haven't even written a UWP app yet, so I'm admittedly a bit behind the times when it comes to client-side apps.

Frankly I like it this way. The web has come a long way, and so many applications that once had to be client apps now make more sense as web applications. I guess I'm just happier using this stack. Though ASP.NET Core 1.0 almost feels like the rug being pulled out from under me; the tooling and process for that is different enough to have a fairly high learning curve.

Quote

Its a shame that it makes me feel like I did C# for 6 months for no reason what so ever except to come to a sign that says "What you just learned doest even matter time to start over"


Don't think of it like that. Really, all your C# experience is still perfectly valid. It's just the UI logic you've learned is a bit out of date. Some concepts still apply, some new concepts apply (like XAML, data binding, and MVVM). But it doesn't mean your experience is useless, it just gives you context.
Was This Post Helpful? 1
  • +
  • -

#14 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 11:15 AM

View PostDOT1, on 12 August 2016 - 11:22 AM, said:

Good point! Curtis.. Its a shame that it makes me feel like I did C# for 6 months for no reason what so ever except to come to a sign that says "What you just learned doest even matter time to start over"
But I'l guess I start picking up on WPF.


Its still C#. 99% of what you write will still be in C#. XAML is just the language for GUI. All the real work in coding takes place under the hood. All that is still C#.

What is going to change between shifting from WinForms to WPF is how your DATA interacts with your GUI. WPF uses a MVVM design pattern that makes so much more possible for smart binding of data to GUI, with less work on your part. Put simply: You'll get a lot more result for a lot less work. Once you get over the learning curve.

But you haven't lost a darned thing with respect to C#.
Was This Post Helpful? 1
  • +
  • -

#15 DOT1   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 02-November 14

Re: How do I rewrite the WPF code to WinForm C# .NET

Posted 12 August 2016 - 11:29 AM

MVVM design pattern is what scares me alot to be honest.

This post has been edited by tlhIn`toq: 12 August 2016 - 11:39 AM
Reason for edit:: No need to quote the entire previous post

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3