Xamarin missing project template?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1195 Views - Last Post: 02 May 2017 - 04:46 PM

#1 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Xamarin missing project template?

Posted 28 April 2017 - 06:52 PM

Hey guys so I am having a problem I am reading a book on Xamarin its called creating mobile apps with xamarin.forms and on page 21 it says for now For now, pick the first one: Blank App (Xamarin.Forms Portable)in Visual Studio or Use Portable Class Library. I don't have those options but I do have cross platform app (Xamarin.forms or native) I picked that one but when I launch into code page 23 says go to the app class but there is only a app.xaml but on page 24 it shows c# code so what do I do now?

This is what the code on page 24 shows

using
System;
using
System.Collect
ions.Generic;
using
System.Linq;
using
System.Text;
using
Xamarin.Forms;
namespace
Hello
{
public
class
App
: 
Application
{
public
App()
{
// The root page of your application
MainPage = 
new
ContentPage
{
Content = 
new
StackLayout
{
VerticalOptions = 
LayoutOptions
.Center,
Children = {
new
Label
{
HorizontalTextAlignment = 
Te
xtAlignment
.Center,
Text = 
"Welcome to Xamarin Forms!"
}
}
}
};
}
protected
override
void
onstart()
{
// Handle when yo
ur app starts
}
protected
override
void
OnSleep()
{
// Handle when your app sleeps
}



has more code my code though looks like this:

namespace Jd
{
	public partial class App : Application
	{
		public App ()
		{
			InitializeComponent();

			MainPage = new Jd.MainPage();
		}

		protected override void onstart ()
		{
			// Handle when your app starts
		}

		protected override void OnSleep ()
		{
			// Handle when your app sleeps
		}

		protected override void onresume ()
		{
			// Handle when your app resumes
		}
	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: Xamarin missing project template?

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 28 April 2017 - 08:35 PM

> page 23 says go to the app class but there is only a app.xaml

Turn the triangle next to app.xaml
You'll see app.xaml.cs decend from the xaml node.

Welcome aboard the Xamarin train!
Was This Post Helpful? 0
  • +
  • -

#3 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 29 April 2017 - 10:55 PM

Thanks. I ended up going with the flow skip the page and its somewhat good now but now the book is not starting to explain the code properly lol.

But yeah realized that line of code poked to the xaml file, but thanks!
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 30 April 2017 - 04:22 AM

> the book is not starting to explain the code

Creating cross-platform mobile apps with Xamarin.Forms - By Charles Petzoid (FREE e-book)
That's not the responsibility of that book. It never claimed to teach C# to the beginner. It's stated purpose is to teach a developer about the Xamarin eco-system.

If you go to the Dale Ernhart school of race car driving, they do not teach basic driver's education to someone that doesn't know how to drive.
Was This Post Helpful? 0
  • +
  • -

#5 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 30 April 2017 - 06:28 AM

Yeah I get that, that's fine but this is completely different to just your regular c#, example is this in the book:

Label CreateColorLabel(Color color, string name)
{
Color backgroundColor = Color.Default;
if(color != Color.Default)
{
// Standard luminance calculation.
double luminance = 0.30 * color.R + 0.59 * color.G + 0.11 * color.B;
backgroundColor = luminance > 0.5 ? 
Color.Black : Color.White;
}
// Create the Label.
return new Label
{
Text = name,
TextColor = color,
FontSize = Device.GetNamedSize(
NamedSize.Large, 
typeof(Label)),
BackgroundColor = backgroundColor
};



Like it doesn't explain why it nests the statements

Also I can't find this but what is this type of syntax called? My usual problem in coding is me asking my self "why is the syntax like this" but what is this type called? Label l = { } and is there any resource so i can find out all the types of syntax used in c#?

This post has been edited by Dialupp: 30 April 2017 - 06:31 AM

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 30 April 2017 - 03:17 PM

> but this is completely different to just your regular c#

No. Its not. That is about as generic of C# as I've ever seen.

> Why it nests the statements
Huh? What are you talking about?

Label CreateColorLabel(Color color, string name)
{
  Color backgroundColor = Color.Default;
   if(color != Color.Default)
   {
      // Standard luminance calculation.
      double luminance = 0.30 * color.R + 0.59 * color.G + 0.11 * color.B;
      backgroundColor = luminance > 0.5 ? 
      Color.Black : Color.White;
   }
   // Create the Label.
   return new Label
   {
      Text = name,
      TextColor = color,
      FontSize = Device.GetNamedSize(
      NamedSize.Large, 
      typeof(Label)),
      BackgroundColor = backgroundColor
   };


> Nested
Are you talking about the code inside the if block? That's not what anyone would call 'nested'. That's just a basic if block.

Are you talking about the block making a new Label and defining the parameters of that Label while creating the instance?

> Also I can't find this but what is this type of syntax called?
Again, those are both really, really basic C# statements. This syntax isn't really called anything. Its just C#. There's nothing unusual or fancy about it.
Was This Post Helpful? 0
  • +
  • -

#7 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 30 April 2017 - 05:01 PM

Oh right nvm I got it mixed up. I was a c# video on it the type of syntax was called something but can't remember what. I'll just experiment with it.
Was This Post Helpful? 0
  • +
  • -

#8 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 30 April 2017 - 05:32 PM

Also there are errors like in the code sample in the book the author didn't declare a variable just set its value but wasn't declared before. Am I not supposed to test this code and just look as example or figure it my self? I am bit confused.
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 01 May 2017 - 01:36 AM

While its certainly possible there are errors... Its unlikely. That book has been through a huge amount of pre-release before version 1 was published.
I'd be curious to know what error(s) you think you found. Let me know and I'd be happy to double check.

Of course you're supposed to do the lessons in the book. Working the lessons is the best way to learn.
Was This Post Helpful? 0
  • +
  • -

#10 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 01 May 2017 - 03:19 AM

Ok so heres one:

 Color[] colors = { Color.Yellow,Color.Blue };
            int flipFlopper = 0;
            // Create Labels sorted by LayoutAlignment property.
            IEnumerable<Label> labels = 
                from field in typeof(LayoutOptions).GetRuntimeFields()
            where field.IsPublic && field.IsStatic
            orderby((LayoutOptions)field.GetValue(null)).Alignment
            select new Label
            {
                Text = "VerticalOptions = " + field.Name,
                VerticalOptions = (LayoutOptions)field.GetValue(null),
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize = Device.GetNamedSize(NamedSize.Medium,typeof(Label)),
                TextColor = colors[flipFlopper],
                BackgroundColor = colors[flipFlopper = 1 - flipFlopper]
            };
       
            stackLayout = new StackLayout();
            foreach(Label label in labels)
            {
                stackLayout.Children.Add(label);
            }
            Padding = new Thickness(0,Device.OnPlatform(20, 0, 0), 0, 0);
            Content = stackLayout;




the error is on these lines

Padding = new Thickness(0,Device.OnPlatform(20, 0, 0), 0, 0);
Content = stackLayout;

basically says for both does not exist in current context, makes sense because no variable declared shouldn't they of declared this? Also with me struggling to understand code in this book especially this sample what should I do?
Was This Post Helpful? 0
  • +
  • -

#11 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 01 May 2017 - 04:40 AM

What page of the book is that?
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 01 May 2017 - 05:14 AM

Found it : Page 93/1197 in the PDF I downloaded.

Its not an error in published code.
Your code missed a line (see the yellow box).

Padding and Content are properties of ContentPage.
Your code isn't showing the class definition where you inherit from ContentPage - and you're saying you're getting errors for those two properties... So my guess is you didn't didn't implement the inheritance.

https://s6.postimg.o...-01_8-05-02.png
Was This Post Helpful? 0
  • +
  • -

#13 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 01 May 2017 - 03:38 PM

Oh yes my mistake I completely forgot about the inheritance. Thanks one last question though what do I do in the case I don't understand the code?

Like this line starting here, its confusing where the hell does it even end?

IEnumerable<Label> labels = from field in typeof(LayoutOptions).GetRuntimeFields()

Why is the layoutOptions in brackets and I never really understand the <> brackets its a generic method but what is use of doing that? I assume its like making a List we define which datatype we want?
Was This Post Helpful? 0
  • +
  • -

#14 Dialupp  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 210
  • Joined: 31-October 16

Re: Xamarin missing project template?

Posted 02 May 2017 - 03:44 AM

Oh btw I know why I didn't understand that code or most of it, its because I didn't know LINQ. Learned it now I am very happy.
Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Xamarin missing project template?

Posted 02 May 2017 - 02:41 PM

> where the hell does it even end?

At the semi-colon, like all C#.

> IEnumerable<Label>

This an an Enumerable of type Label. IEnumberable is an interface (hence the 'I') - that can be Enumerated through. You can make/override the method that does the enumerating. For example: If you only want to return/yield all the objects out of a collection where the connection status is true and the background color is yellow... Or whatever specific need you have.

Or you can just leave it at default and enumerate through all members of the collection.

> Thanks one last question though what do I do in the case I don't understand the code?
Read more C# text books.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2