SampleCrossUi.Maui 1.0.0.0
SampleCrossUi.Maui 사용 방법을 보여 주는 예제 프로젝트입니다.
로딩중...
검색중...
일치하는것 없음
ControlsPage.xaml.cs
이 파일의 문서화 페이지로 가기
1using SampleCrossUi.Shared.ViewModels;
2
4
13public partial class ControlsPage : ContentView
14{
23 private readonly ControlsViewModel _viewModel;
32 private readonly (string Title, VerticalStackLayout Content)[] _tabs;
41 private Button? _selectedTabButton;
42
59 public ControlsPage(ControlsViewModel viewModel)
60 {
61 InitializeComponent();
62 _viewModel = viewModel;
63 BindingContext = _viewModel;
64
65 RadioOptionA.IsChecked = _viewModel.SelectedRadio == "Option A";
66 RadioOptionB.IsChecked = _viewModel.SelectedRadio == "Option B";
67
68 VirtualKeyboard.Attach(MainEntry);
69
70 _tabs = new (string, VerticalStackLayout)[]
71 {
72 ("Button", TabButton),
73 ("CheckBox / Radio", TabCheckRadio),
74 ("CheckLed", TabCheckLed),
75 ("TextBox", TabTextBox),
76 ("ComboBox", TabComboBox),
77 ("DataGrid / ListBox", TabGridList),
78 ("Misc", TabMisc),
79 };
80
81 foreach (var (title, content) in _tabs)
82 {
83 var tabButton = new Button
84 {
85 Text = title,
86 BackgroundColor = Color.FromArgb("#0D1B3E"),
87 TextColor = Colors.White,
88 CornerRadius = 6,
89 FontSize = 12,
90 Padding = new Thickness(10, 4)
91 };
92 tabButton.Clicked += (_, _) => SelectTab(content, tabButton);
93 TabRow.Children.Add(tabButton);
94
95 if (content == TabButton)
96 {
97 _selectedTabButton = tabButton;
98 tabButton.BackgroundColor = Color.FromArgb("#0d6efd");
99 }
100 }
101 }
102
127 private void SelectTab(VerticalStackLayout target, Button tabButton)
128 {
129 foreach (var (_, content) in _tabs)
130 content.IsVisible = content == target;
131
132 if (_selectedTabButton is not null)
133 _selectedTabButton.BackgroundColor = Color.FromArgb("#0D1B3E");
134
135 tabButton.BackgroundColor = Color.FromArgb("#0d6efd");
136 _selectedTabButton = tabButton;
137 }
138
163 private void OnVariantButtonClicked(object? sender, EventArgs e)
164 {
165 if (sender is Button button)
166 ButtonTabStatus.Text = $"[{DateTime.Now:HH:mm:ss}] '{button.Text}' 버튼이 클릭되었습니다.";
167 }
168
193 private void OnRadioCheckedChanged(object? sender, CheckedChangedEventArgs e)
194 {
195 if (!e.Value || sender is not RadioButton radio)
196 return;
197
198 var option = radio.Content?.ToString() ?? string.Empty;
199 _viewModel.SelectRadioCommand.Execute(option);
200 }
201
226 private void OnGridSelectionChanged(object? sender, SelectionChangedEventArgs e)
227 {
228 GridSelectionLabel.Text = e.CurrentSelection.FirstOrDefault() is ControlsDemoRow row
229 ? $"선택된 행: No.{row.No} {row.Name} ({row.Status})"
230 : "(선택된 행 없음)";
231 }
232
257 private void OnFruitItemDoubleTapped(object? sender, TappedEventArgs e)
258 {
259 if (sender is Label { Text: { } text })
260 _viewModel.ListBoxActivatedCommand.Execute(text);
261 }
262
287 private async void OnLogClickClicked(object? sender, EventArgs e)
288 {
289 _viewModel.ClickMeCommand.Execute(null);
290 await Task.Delay(50);
291 if (_viewModel.ActivityLog.Count > 0)
292 LogList.ScrollTo(_viewModel.ActivityLog[^1], position: ScrollToPosition.End, animate: true);
293 }
294}
void OnGridSelectionChanged(object? sender, SelectionChangedEventArgs e)
void OnRadioCheckedChanged(object? sender, CheckedChangedEventArgs e)
void SelectTab(VerticalStackLayout target, Button tabButton)
readonly(string Title, VerticalStackLayout Content)[] _tabs
void OnFruitItemDoubleTapped(object? sender, TappedEventArgs e)
void OnVariantButtonClicked(object? sender, EventArgs e)
ControlsPage(ControlsViewModel viewModel)
readonly ControlsViewModel _viewModel
async void OnLogClickClicked(object? sender, EventArgs e)