Hello Devs! I was using FreshMVVM in my Xamarin Forms Project, I implement Button Command in my LoginPage but it seems the Button doesn't have any connection with the LoginPageModel, I use XF Material Library and the Register button which I bound to is the Last Control in the Page (to ease Navigation).
Here is the LoginPage.Xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns:local="clr-namespace:buziTrade.Pages"
xmlns:xamanimation="clr-namespace:Xamanimation;assembly=Xamanimation"
xmlns:material="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
xmlns:yummy="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
mc:Ignorable="d"
x:Class="buziTrade.Pages.LoginPage"
NavigationPage.HasNavigationBar="False">
<ContentPage.Resources>
<ResourceDictionary>
<local:MultiTriggerConverter x:Key="dataHasBeenEntered" />
<!--<xamanimation:StoryBoard
x:Key="InfoPanelAnimation"
Target="{x:Reference InfoPanel}">
<xamanimation:FadeToAnimation
Duration="50"
Opacity="1" />
<xamanimation:TranslateToAnimation
TranslateY="0"
Easing="CubicIn"
Duration="100" />
</xamanimation:StoryBoard>-->
<xamanimation:FadeInAnimation
x:Key="FlexLayoutAnimation"
Target="{x:Reference MainPanel}"
Duration="300"/>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<Grid x:Name="MainPanel">
<Grid VerticalOptions="Start">
<!--<yummy:PancakeView BackgroundColor="#275685" VerticalOptions="Start"
Padding="10">
<Label Text="Login Form" FontSize="14" TextColor="#FFFFFF"
FontAttributes="Bold"/>
</yummy:PancakeView>-->
<Frame BackgroundColor="#275685"
HorizontalOptions="Center" WidthRequest="30"
HeightRequest="30" CornerRadius="5"
Margin="0, 40, 0, 0">
<Label Text="bt" TextColor="White" HorizontalOptions="Center"
VerticalOptions="Center" FontSize="Large"
FontAttributes="Bold"/>
</Frame>
<Label Text="buziTrade"
TextColor="#275685" VerticalOptions="EndAndExpand"
HorizontalOptions="CenterAndExpand" Margin="0,0,0,-30"/>
</Grid>
<Grid VerticalOptions="CenterAndExpand" Margin="20,60,20,0">
<StackLayout>
<material:MaterialTextField Margin="0,0,0,30"
Placeholder="Username" x:Name="UserName"
InputType="Text" MaxLength="10" TintColor="#EC8D34"
FloatingPlaceholderFontSize="10" ShouldAnimateUnderline="True"
AlwaysShowUnderline="True"/>
<material:MaterialTextField
Placeholder="Password" x:Name="Password"
InputType="Password" MaxLength="8" TintColor="#EC8D34"
FloatingPlaceholderFontSize="10" ShouldAnimateUnderline="True"
AlwaysShowUnderline="True"/>
<StackLayout Orientation="Horizontal" VerticalOptions="End"
FlowDirection="RightToLeft" Margin="0,30,0,0">
<material:MaterialButton BackgroundColor="#275685"
CornerRadius="5" Margin="15, 10, 0, 0" Text="Login"
TextColor="#FFFFFF" ButtonType="Elevated"
x:Name="BtnLog2" IsEnabled="False">
<Button.Triggers>
<MultiTrigger TargetType="Button">
<MultiTrigger.Conditions>
<BindingCondition Binding="{Binding Source={x:Reference UserName},
Path=Text.Length,
Converter={StaticResource dataHasBeenEntered}}"
Value="True"/>
<BindingCondition Binding="{Binding Source={x:Reference Password},
Path=Text.Length,
Converter={StaticResource dataHasBeenEntered}}"
Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="IsEnabled" Value="True" />
</MultiTrigger>
</Button.Triggers>
</material:MaterialButton>
<material:MaterialButton
TextColor="Red" FontSize="13"
ButtonType="Flat"
BackgroundColor="Transparent"
PressedBackgroundColor="Transparent"
CornerRadius="5" Margin="0,10,0,0"
Text="Forgot Password!"
HorizontalOptions="EndAndExpand" />
<!--<material:MaterialButton
CornerRadius="5" Margin="0, 10, 0, 0"
Text="Forgot Password!" BackgroundColor="#FFFFFF"
TextColor="#FFFFFF" ButtonType="Text"
PressedBackgroundColor="Transparent"
x:Name="Btnforgot" HorizontalOptions="EndAndExpand"/>-->
</StackLayout>
</StackLayout>
</Grid>
<StackLayout Orientation="Horizontal" VerticalOptions="End" Margin="0, 0, 0, 90">
<BoxView HorizontalOptions="StartAndExpand" VerticalOptions="Center" BackgroundColor="#275685" HeightRequest="2"
WidthRequest="150"/>
<Label Text="OR" HorizontalOptions="Center" VerticalOptions="Center" TextColor="#275685"/>
<BoxView HorizontalOptions="EndAndExpand" VerticalOptions="Center" BackgroundColor="#275685" HeightRequest="2"
WidthRequest="150"/>
</StackLayout>
<material:MaterialButton
CornerRadius="5" Margin="0, 0, 0, 30"
Text="Register Here" BackgroundColor="#FFFFFF"
TextColor="#275685" ButtonType="Text"
PressedBackgroundColor="Transparent"
x:Name="BtnRegister" VerticalOptions="End"
Command="{Binding RegisterCommand}" />
</Grid>
</ContentPage.Content>
</ContentPage>
and this is the LoginPageModel:
using FreshMvvm;
using PropertyChanged;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace buziTrade.PageModels
{
[AddINotifyPropertyChangedInterface]
public class LoginPageModel : FreshBasePageModel
{
public ICommand RegisterCommand => new Command(async () => await RegisterPage());
public LoginPageModel()
{
}
public override void Init(object initData)
{
base.Init(initData);
}
private async Task RegisterPage()
{
await CoreMethods.PushPageModel<RegisterPageModel>();
}
}
}
@MichaelRidland @Martijn00