Reputation: 23
I newly started to code. Alhought Helloworld code, I get this error: xamarin.forms.xamlparseexception: position 12:13 cannot assign property "click": Property does not exists, or is not assignable, or mismatching type between value and property
The device that I want to debug king wear smart watch KW88-android 5.1.
code:
namespace HelloWorld
{
[global::Xamarin.Forms.Xaml.XamlFilePathAttribute("C:\\Users\\Gizem\\source\\repos\\HelloWorld\\HelloWorld\\HelloWorld\\MainPage.xaml")]
public partial class MainPage : global::Xamarin.Forms.ContentPage {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(MainPage));//Exception here!!!*****
}
}
}
xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:HelloWorld"
x:Class="HelloWorld.MainPage">
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Entry Placeholder="Write your name"/>
<Button Text="say hello"
Click="Button_Click"/>
xaml.cs:
using System;
using Xamarin.Forms;
namespace HelloWorld
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
void Button_Click(object sender, EventArgs e)
{
}
}
}
Upvotes: 2
Views: 316
Reputation: 1582
The property to bind to is named Clicked
, not Click
. change your code to
<Button Text="say hello"
Clicked="Button_Click"/>
and it should work.
EDIT
Alessandro Caliaro makes a very good point in that a ContentPage can only contain a single element. So you would also need to wrap your controls into a container, for example a StackLayout
:
<StackLayout VerticalOptions="Center" >
<Label Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center" />
<Entry Placeholder="Write your name"/>
<Button Text="say hello"
Clicked="Button_Click"/>
</StackLayout>
Upvotes: 1
Reputation: 5768
I think you should add your controls to a layout (Like StackLayout) otherwise other problems could came.
Upvotes: 1