Issue
I have a problem. I am using the following fabmenu: https://github.com/Polarts/CrossFAB
Now I want to bind a command to the fabmenu buttons, so I did the following in page1.xaml:
<c:FloatingMenu Margin="0, 0, 10, 10" BGColor="#56D7A5" OpenIcon="openFab_icon" CloseIcon="closeFab_icon"
AbsoluteLayout.LayoutBounds=".95,.95" AbsoluteLayout.LayoutFlags="PositionProportional">
<c:FloatingButton x:Name="page1" BGColor="#59E1FF" IconSrc="page1" OnClickCommand="{Binding btnPage2Command}" />
</c:FloatingMenu>
And in page1.xaml.cs I did the following:
public partial class page1 : ContentPage
{
public ICommand btnPage2Command{ get; set; }
public page1()
{
InitializeComponent();
btnPage2Command= new Command(OpenPage2);
}
private async void OpenPage2()
{
await Application.Current.MainPage.Navigation.PushAsync(new page2());
}
}
But I get the following error:
No property, bindable property, or event found for 'OnClickCommand', or mismatching type between value and property.
UPDATE:
I have now added the BindingContext, but I get the following error:
Object reference not set to an instance of an object
at this line in the FloatingButton.xaml.cs (see https://github.com/Polarts/CrossFAB):
OnClickCommand.Execute(null);
How can I fix this?
Solution
You need a Binding Context. Therefore you can assign it in the constructor or the xaml file.
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
....
x:Name="this">
And there you want to use it
<c:FloatingMenu Margin="0, 0, 10, 10" BGColor="#56D7A5" OpenIcon="openFab_icon" CloseIcon="closeFab_icon"
AbsoluteLayout.LayoutBounds=".95,.95" AbsoluteLayout.LayoutFlags="PositionProportional">
<c:FloatingButton BindingContext="{x:Reference this}" x:Name="page1" BGColor="#59E1FF" IconSrc="page1" OnClickCommand="{Binding btnPage2Command}" />
</c:FloatingMenu>
Answered By - Daniel Klauser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.