C# WINDOWS MAUI專案 使用ContentView(XAML) 建立自訂複合元件(Custom Composite Components)

C# WINDOWS MAUI專案 使用ContentView(XAML) 建立自訂複合元件(Custom Composite Components)

C# WINDOWS MAUI專案 使用ContentView(XAML) 建立自訂複合元件(Custom Composite Components)


資料來源: [youtube: c# maui custom button] ~ https://www.youtube.com/watch?v=3Cd3amJ-qcw (.NET MAUI – Building your own custom controls)


GITHUB: https://github.com/jash-git/MAUI_WinAPI_Object_test/tree/main/Code/08


CardControl.xaml code

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MAUI_WinAPI_Object_test.CustomControls.CardControl">
    <VerticalStackLayout>
        <Label
            x:Name="Titlelabel"
            Text="Welcome to .NET MAUI!"
            VerticalOptions="Center" 
            HorizontalOptions="Center" />
    </VerticalStackLayout>
</ContentView>


CardControl.xaml.cs code

namespace MAUI_WinAPI_Object_test.CustomControls;
/*
.NET MAUI - Building your own custom controls

*/
public partial class CardControl : ContentView
{
    public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(CardControl), propertyChanged: (bindable, oldValue, newValue) =>
	{
		var control= (CardControl)bindable;
		control.Titlelabel.Text=newValue as string;
	});
    public string Title
	{
		get =>GetValue(TitleProperty) as string;
		set => SetValue(TitleProperty, value);
	}

    public CardControl()
	{
		InitializeComponent();
	}
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *