Hi,
I'm struggling with some XAML syntax. In this first piece of code, I have attached a command to a button in the button's attributes:
="1.0"="utf-8"
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyAssembly.CodeBehindClass">
<StackLayout>
<Button x:Name="buttonName" Text="Press" Command="{Binding ButtonOnClickedCommand}" />
</StackLayout>
</ContentPage>
This works fine. But what if I want to use the alternative syntax as shown below? I can set the text no problem, but I can't figure out how to bind the command:
="1.0"="utf-8"
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyAssembly.CodeBehindClass">
<StackLayout>
<Button x:Name="buttonName">
<Button.Text>Press</Button.Text>
<Button.Command>STRUGGLING FOR SYNTAX HERE</Button.Command>
</StackLayout>
</ContentPage>
I think I can express my question more simply as follows:
In general, in XAML, if you have a UI element with a property then you can set the property one of two ways. You can either do this:
<MyControl MyProperty="Value-which-may-be-a-binding-expression"/>
Or you can achieve exactly the same thing like this:
<MyControl>
<MyControl.MyProperty>Value-goes-here</MyControl.MyProperty>
</MyControl>
I can get this to work with various properties but can't work out how to do it with the
Command. But I think my problem is not specifically the
Command property; I think it is the fact that I don't know how to write a binding expression using the second syntax above.
Hope this makes sense.
Kind wishes ~ Patrick