728x90
728x170

Person.cs

namespace Maui.DevExpressTest.Models
{
    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public string Location { get; set; }
    }
}

MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="Maui.DevExpressTest.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:dxe="clr-namespace:DevExpress.Maui.Editors;assembly=DevExpress.Maui.Editors">

    <ScrollView>
        <VerticalStackLayout
            Padding="30,0"
            Spacing="25"
            VerticalOptions="Center">

            <dxe:ComboBoxEdit
                DisplayMember="Name"
                ItemsSource="{Binding Persons}"
                LabelText="Person"
                SelectedIndex="1">
                <dxe:ComboBoxEdit.ItemTemplate>
                    <DataTemplate>
                        <Grid ColumnDefinitions="*,*,*">
                            <Label
                                Padding="10"
                                FontAttributes="Bold"
                                Text="{Binding Name}" />
                            <Label
                                Grid.Column="1"
                                Padding="10"
                                Text="{Binding Age}" />
                            <Label
                                Grid.Column="2"
                                Padding="10"
                                HorizontalTextAlignment="End"
                                Text="{Binding Location}" />
                        </Grid>
                    </DataTemplate>
                </dxe:ComboBoxEdit.ItemTemplate>
            </dxe:ComboBoxEdit>

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

MainViewModel.cs

using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;

using Maui.DevExpressTest.Models;

namespace Maui.DevExpressTest.ViewModels
{
    public class MainViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        private ObservableCollection<Person> persons;

        public ObservableCollection<Person> Persons
        {
            get
            {
                if (this.persons == null)
                {
                    this.persons = new ObservableCollection<Person>();
                }

                return this.persons;
            }
            set
            {
                this.persons = value;
                OnPropertyChanged();
            }
        }

        public MainViewModel()
        {
            Persons.Add(new Person() { Name = "Devid", Age = 45, Location = "Atlanta" });
            Persons.Add(new Person() { Name = "Bernda", Age = 23, Location = "Memphis" });
            Persons.Add(new Person() { Name = "Sean", Age = 36, Location = "Hiuston" });
        }
    }
}

실행결과

[Source]
https://github.com/kei-soft/Maui.DevExpressTest

728x90
그리드형
Posted by kjun.kr
,