MobileEssentials / FormsPlayer

Xamarin Forms Player Demo
MIT License
79 stars 24 forks source link

Crash on xaml with Button #4

Closed MBrekhof closed 9 years ago

MBrekhof commented 9 years ago

Hi, the follwing xaml works but crashes the player. Any hints how to solve this? Removing the Clicked="Button_OnClicked" solves it but then I have no functionality.

 <?xml version="1.0" encoding="utf-8" ?>
 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="TimMobile.Login">
 <ContentPage.Content>
 <StackLayout VerticalOptions="Center">
  <StackLayout.Children>
    <Label XAlign="Start" Text="Naam"></Label>
    <Entry x:Name="Naam" Text="Naam" InputTransparent="True"></Entry>
    <Label XAlign="Start" Text="Password"></Label>
    <Entry x:Name="Password" Text="Password" InputTransparent="True" IsPassword="True"> 
    </Entry>
    <Button x:Name ="btnLogin" Text="Login"  Clicked="Button_OnClicked" />

  </StackLayout.Children>
  </StackLayout>
  </ContentPage.Content>
 </ContentPage>
kzu commented 9 years ago

You can't have any custom functionality deployed magically to the device. All the FormsPlayer receives is XAML and Json. It can't receive your custom base class for your screen.

The way to deal with commands in XAML/WPF/XF properly is to actually data bind the button's Command property to a command on the view model, like this XML and its corresponding view model. You can find lots of examples like that elsewhere.

With command binding in place, it should all just work and you don't need to change your XAML in order to preview it. Also, keep in mind you can push a Json view model too to simulate the different screen states.