■ EntryHandler 클래스의 Mapper 정적 속성을 사용해 특정 컨트롤 인스턴스를 설정하는 방법을 보여준다. (ANDROID) (IOS) (WINDOWS)
▶ CustomEntry.cs
1 2 3 4 5 6 7 8 9 10 11 |
namespace TestProject { /// <summary> /// 커스텀 엔트리 /// </summary> public class CustomEntry : Entry { } } |
▶ App.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using Microsoft.Maui.Platform; namespace TestProject; /// <summary> /// 앱 /// </summary> public partial class App : Application { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - App() /// <summary> /// 생성자 /// </summary> public App() { InitializeComponent(); MainPage = new MainPage(); Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping ( nameof(IView.Background), (handler, view) => { if(view is CustomEntry) { #if ANDROID handler.PlatformView.SetBackgroundColor(Colors.Red.ToPlatform()); #elif IOS handler.PlatformView.BackgroundColor = Colors.Red.ToPlatform(); handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.Line; #elif WINDOWS handler.PlatformView.Background = Colors.Red.ToPlatform(); #endif } } ); } #endregion } |
▶ MainPage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="TestProject.MainPage" xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:TestProject"> <StackLayout HorizontalOptions="Center" VerticalOptions="Center"> <Label Text="Label" /> <Button Margin="0,10,0,0" Text="Button" /> <local:CustomEntry Margin="0,10,0,0" MinimumWidthRequest="100" /> </StackLayout> </ContentPage> |