ARTICLE AD BOX
Is there a way to compile a binding in an ordinary content page when there is no view model?
I have a content page with the bindable property "backgroundcolor" and it works fine to set the button backgroundcolor:
public partial class EditPage : ContentPage { //Background color private readonly BindableProperty bBackgroundcolor = BindableProperty.Create(nameof(backgroundcolor), typeof(Color), typeof(EditPage)); public Color backgroundcolor { get => (Color)GetValue(bBackgroundcolor); set => SetValue(bBackgroundcolor, value); } public EditPage(SleepDateWithBoolean CurrentSleepDateEditPopup) { InitializeComponent(); BindingContext = this; ... } }I have the XAML code:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SleepDiary.EditPage" Title="EditPage"> <VerticalStackLayout> <Button x:Name="SaveAndCloseButton" Text="Save and close" BackgroundColor="{Binding backgroundcolor}" Clicked="SaveAndClose"/> </VerticalStackLayout> </ContentPage>I get the warning below when I compile:
"Binding could be compiled to improve runtime performance if x:DataType is specified. See https://learn.microsoft.com/dotnet/maui/fundamentals/data-binding/compiled-bindings for more information."
Is there a way to compile a binding in an ordinary content page when there is no view model?
I understand one should use "x:DataType" but I am unable to find out what to write?
<Button x:Name="SaveAndCloseButton" Text="Save and close" BackgroundColor="{Binding backgroundcolor, x:DataType=???}" Clicked="SaveAndClose"/>Thanks in advance!
