11 Replies - 1425 Views - Last Post: 14 March 2018 - 03:08 PM

#1 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

What is the Proper Method for Changing an .XML File w/Buttons

Posted 14 February 2018 - 03:48 PM

Hey all,
I've recently gotten back into development for Android using Xamarin and I am eventually going to be developing an iOS clone of the app I am working on. I am wondering what the most efficient/proper way to change an XML file based upon a button click event is? In VC++ i would do something like this:

private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) 
{
	     label8->ForeColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>  (static_cast<System::Byte>(h)), static_cast<System::Int32>(static_cast<System::Byte>(0)),
	       static_cast<System::Int32>(static_cast<System::Byte>(253)));
}



However, in C#/XML there are two separate files, so how does one go about changing a value in the XML file using the classes contained in our .cs file? Should I have the XML UI reference a value that is contained in the C# .cs file or is it possible to create logic within the xml file that asks the class which color to be?

Forgive me, Xamarin is a lot harder than what I'm used to; because I'm still learning the ropes about how to cross reference between the two. Sorry if this is a n00b question but even understanding a basic concept like this will help me expand upon it in the future.

Thanks in advance :)

Is This A Good Question/Topic? 0
  • +

Replies To: What is the Proper Method for Changing an .XML File w/Buttons

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6798
  • View blog
  • Posts: 28,093
  • Joined: 12-December 12

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 15 February 2018 - 08:28 AM

I am confused, what has that code to do with XML?

Is the XML you are trying to write to a configuration file, or some custom file that you have created?

Explain why clicking some button should change something in an XML file.



(Is Xamarin very similar to WPF?) In which case you would be using Commands (ICommand) rather than directly wiring to UI events. [Based on your response to my preceding questions, I also question whether you need to directly write to XML at all.]

But this is just a passing comment, not something I'm in a position to pursue further. Someone else here might comment ;)
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

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

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 15 February 2018 - 10:27 AM

Your code looks like 1995 Windows Forms. No XAML binding or property MVVM to be seen. Did you ever do anything in WPF?

Xamarin is in many ways just the next evolution of WPF. If you are famility with binding and commands in WPF its the same in Xamarin. The cross-platform nature of the eco-system doesn't affect that at all.

The fact that you're trying to do logic in a button.click event worries me. Have you done through any of the Xamarin University Courses? Many are on YouTube for free.

Or at the very least hit up my short tutorial series. http://www.RedPillXamarin.com to get started in the right direction and not along this button.click path you're on.

Further re-reading of your post.....

> In VC++ i would do something like this:
Oh. Wow. So you're going from 25 years ago to today in one leap. That's a big nut to crack.

>I am confused, what has that code to do with XML?
>> However, in C#/XML there are two separate files, so how does one go about changing a value in the XML file using the classes contained in our .cs file?

Its the OP that is confused. First its XAML not XML. You don't change the XAML from your csharp code behind. Your thinking is from the 1990's perspective of trying to push changes from code to UI. We don't do things that way anymore - not in the last 15-ish years since WPF came out. The pattern these days is to bind elements of the UI to properties on a ViewModel.

Example:
If you have a UI showing the properties of your pet, you bind the Icon.Source to a property on your PetViewModel If the pet is a dog, then the source is the dog image. If the pet is a cat, then the source points to the png of a cat. There is no action that takes place... you don't have code that executes forcing a change from A to B. When the selected pet changes, all the properties on your view update automatically because they are binded along a path..... SelectedPet.Species


If you're going from VC++ to modern C#/XAML/MVVM you've got a huge technological deficient to get over. Literally decades of new practices and patterns to catch up on. There's lots of tutorials out there like mine but they mostly assume the reader is fairly up to date: They don't try to cover the last 15-20 years of advances. I would URGE you to sign up for Xamarin University and start with their basic C# courses and move forward from there. You've got a lot of foundation concepts to catch-up on before you can start considering any app development. Fortunatley XamU is a flat-rate system where you can take as many courses as you can fit into your day. Since many of their teachers are in other countries like Australia I found the scheduling to be almost around-the-clock so should work regardless of your work schedule.
Was This Post Helpful? 2
  • +
  • -

#4 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 01 March 2018 - 09:14 AM

Lol sorry man, I'm still learning.... i never claimed to be an expert

@tlhIn`toq I'm checking out your website now. thanks man!
Was This Post Helpful? 0
  • +
  • -

#5 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 01 March 2018 - 09:58 AM

Thanks for clearing that up about XML vs XAML .. I've got some web design experience so I was like "Oh, I know this language!" ... it seems pretty similar so that's why I was confused. Sorry about my n00bishness
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

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

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 01 March 2018 - 10:09 AM

No worries mate. XAML is very much like XML. Makes picking it up pretty easy. Kinda like if you already speak American English, Australian English isn't a big stretch even though there are cultural differences in the language.
Was This Post Helpful? 1
  • +
  • -

#7 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 02 March 2018 - 08:16 AM

I'm going to be checking out your site all day today! Looks like a lot of great info, I'm starting from the beginning as if I knew nothing. I've already got a baseline understanding (enough to get a functional app published) but I think I could use a bit of lesson learning here before I go too much further into my next project (which will be far more complex).

How much experience do you have with webview for mobile (iOS, Android)?
Was This Post Helpful? 0
  • +
  • -

#8 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 02 March 2018 - 09:08 AM

@tlhIn`toq I tried the cross platform template when I first started this current project and there were all sorts of compiler errors; but your tutorial has inspired me to go back and try it again! One thing with Xamarin that I've noticed is that sometimes there are random errors and they go away for no apparent reason. I still love their IDE though. I've used Android studio and the look, feel, performance, smoothness of Xamarin is wayyy better IMO. It just looks and runs crispier in VS2017/2015 .. android studio seemed to be slightly more stable though.

anywhoo, really a pleasure to check this info out! thanks for sharing man
Was This Post Helpful? 0
  • +
  • -

#9 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 09 March 2018 - 04:35 PM

View PosttlhIn`toq, on 01 March 2018 - 10:09 AM, said:

No worries mate. XAML is very much like XML. Makes picking it up pretty easy. Kinda like if you already speak American English, Australian English isn't a big stretch even though there are cultural differences in the language.


Your site is down homie! Please restore lol, been a busy week and I haven't had a chance to read some of the stuff that I wanted to read off there
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

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

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 10 March 2018 - 04:26 AM

View Posthexagod, on 09 March 2018 - 06:35 PM, said:

View PosttlhIn`toq, on 01 March 2018 - 10:09 AM, said:

No worries mate. XAML is very much like XML. Makes picking it up pretty easy. Kinda like if you already speak American English, Australian English isn't a big stretch even though there are cultural differences in the language.


Your site is down homie! Please restore lol, been a busy week and I haven't had a chance to read some of the stuff that I wanted to read off there



Damn. I just posted an update on 06mar. Whiskey Tango Foxtrot!?
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

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

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 10 March 2018 - 09:11 PM

Give it a go now. I am trying to get the XML-RPC working and accidentally whacked up the .htaccess. I looks fixed and accessible now.
Was This Post Helpful? 1
  • +
  • -

#12 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: What is the Proper Method for Changing an .XML File w/Buttons

Posted 14 March 2018 - 03:08 PM

thanks man! Yeah I've beeen super busy but your website is a huge help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1