iconDreamine
← 지식 Q&A 목록
ViewModel · Published

Dreamine에서는 XAML 버튼과 ViewModel의 메서드를 어떻게 연결하나요?

요청 판정 Supported 개정 1 / 1 조회 535초 동안 분석2026-07-20 23:21
직접 답변

ViewModel의 `partial` 메서드에 `[DreamineCommand("호출 대상")]`를 붙이고, XAML 버튼의 `Command`를 생성된 `<메서드명>Command`에 바인딩합니다. 예: `ClickMe()` → `ClickMeCommand`.

핵심 코드 근거

직접 근거

ClickMe 코드 선언

stable URI로 확인한 실제 선언 일부입니다.

[DreamineCommand] ClickMe()
    [DreamineCommand("Event.ClickMe")]
    private partial void ClickMe();
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Shared/ViewModels/ControlsViewModel.cs:56-57
직접 근거

ControlsDemoRow.ClickMe 코드 선언

stable URI로 확인한 실제 선언 일부입니다.

[DreamineCommand] ClickMe()
    [DreamineCommand("Event.ClickMe")]
    private partial void ClickMe();
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Shared/ViewModels/ControlsViewModel.cs:56-57
직접 근거

ControlsDemoRow.ClickMe 코드 선언

stable URI로 확인한 실제 선언 일부입니다.

[DreamineCommand("Event.ClickMe")]
    [DreamineCommand("Event.ClickMe")]
    private partial void ClickMe();
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Shared/ViewModels/ControlsViewModel.cs:56-57
직접 근거

ControlsEvent.ClickMe 코드 선언

stable URI로 확인한 실제 선언 일부입니다.

ControlsEvent.ClickMe()
    public void ClickMe()
    {
        ClickCount++;
        ActivityLog.Add($"[{DateTime.Now:HH:mm:ss}] Clicked ({ClickCount})");
        Raise($"Button clicked {ClickCount} time(s)");
    }

    // ── RadioButton ───────────────────────────────────────
    public string SelectedRadio { get; private set; } = "Option A";

    public void SelectRadio(string? option)
    {
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Shared/ViewModels/ControlsEvent.cs:26-37
직접 근거

ControlsPage.ClickMeCommand 코드 선언

stable URI로 확인한 실제 선언 일부입니다.

Command="{Binding ClickMeCommand}"

                <!-- ① Button -->
                <VerticalStackLayout x:Name="TabButton" Spacing="12">
                    <Label Text="Button" FontAttributes="Bold" FontSize="16" />
                    <Button Text="{Binding ClickCount, StringFormat='Click Me ({0})'}"
                            Command="{Binding ClickMeCommand}"
                            BackgroundColor="#0d6efd" TextColor="White" />

                    <Label Text="Color Variants" FontAttributes="Bold" />
                    <HorizontalStackLayout Spacing="8">
                        <Button Text="Primary" BackgroundColor="#0d6efd" TextColor="White" WidthRequest="90" Clicked="OnVariantButtonClicked" />
                        <Button Text="Success" BackgroundColor="#198754" TextColor="White" WidthRequest="90" Clicked="OnVariantButtonClicked" />
                        <Button Text="Warning" BackgroundColor="#ffc107" TextColor="Black" WidthRequest="90" Clicked="OnVariantButtonClicked" />
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Maui/Views/ControlsPage.xaml:18-30
직접 근거

DreamineCommand generated property naming rule 코드 선언

stable URI로 확인한 실제 선언 일부입니다.

return methodName + "Command";
            {
                return commandNameOverride!;
            }

            return methodName + "Command";
        }
20_SOURCES/100. Library/Generators/DreamineCommandSourceGenerator.cs:300-305
직접 근거

MAUI 버튼의 Command 바인딩 코드 선언

버튼이 `ClickMeCommand`에 바인딩됩니다.

Command="{Binding ClickMeCommand}"

                <!-- ① Button -->
                <VerticalStackLayout x:Name="TabButton" Spacing="12">
                    <Label Text="Button" FontAttributes="Bold" FontSize="16" />
                    <Button Text="{Binding ClickCount, StringFormat='Click Me ({0})'}"
                            Command="{Binding ClickMeCommand}"
                            BackgroundColor="#0d6efd" TextColor="White" />
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Maui/Views/ControlsPage.xaml:18-25
직접 근거

WPF 버튼의 Command 바인딩 코드 선언

DreamineButton 역시 `ClickMeCommand`에 바인딩됩니다.

Command="{Binding ClickMeCommand}"
                            <StackPanel>
                                <TextBlock Text="기본 버튼 — Background / Foreground" Style="{StaticResource CardTitle}" />
                                <WrapPanel>
                                    <ctrl:DreamineButton Content="Primary" Foreground="White"
                                        Background="#FF1E90FF" Width="100" Height="34" Margin="0,0,8,8"
                                        Command="{Binding ClickMeCommand}" />
                                    <ctrl:DreamineButton Content="Secondary" Foreground="White"
                                        Background="#FF2D4A6E" Width="100" Height="34" Margin="0,0,8,8"
                                        Command="{Binding ClickMeCommand}" />
                                    <ctrl:DreamineButton Content="Success" Foreground="White"
                                        Background="#FF1B7A3E" Width="100" Height="34" Margin="0,0,8,8"
                                        Command="{Binding ClickMeCommand}" />
                                    <ctrl:DreamineButton Content="Warning" Foreground="White"
20_SOURCES/998. DEMO/000. Sample/050. CrossUi/SampleCrossUi.Wpf/Views/ControlsView.xaml:155-167

추가 설명

2. XAML 버튼 바인딩

버튼의 `Command` 속성을 생성된 커맨드에 연결합니다. ```xml <Button Text="{Binding ClickCount, StringFormat='Click Me ({0})'}" Command="{Binding ClickMeCommand}" /> ``` WPF의 `DreamineButton`도 동일하게 `Command="{Binding ClickMeCommand}"`를 사용합니다.

확인되지 않은 내용

  • ControlsViewModel이 MAUI의 BindingContext 또는 WPF의 DataContext로 설정되는 정확한 코드 위치는 제공된 발췌만으로 확인되지 않습니다.
기술 세부정보

정규화된 질문: Dreamine에서는 XAML 버튼과 ViewModel의 메서드를 어떻게 연결하나요?

Source · ControlsViewModel의 DreamineCommand 선언 source-1 · 직접 근거 · confidence 1.00
Source · DreamineCommand 생성 이름 규칙 source-2 · 직접 근거 · confidence 1.00
Source · MAUI 버튼의 Command 바인딩 source-3 · 직접 근거 · confidence 1.00
Source · WPF 버튼의 Command 바인딩 source-4 · 직접 근거 · confidence 1.00
Source · ControlsEvent의 실제 클릭 처리 source-5 · 직접 근거 · confidence 1.00
Source · CounterEvent의 Service 의존성 source-6 · 직접 근거 · confidence 1.00
Source · bindsCommand ControlsPage.ClickMeCommand trace-xaml-binding · 직접 근거 · confidence 1.00
Source · generatesCommand DreamineCommand generated property naming rule trace-generator-rule · 직접 근거 · confidence 1.00
Source · declaresCommandMethod ControlsDemoRow.ClickMe trace-viewmodel-command · 직접 근거 · confidence 1.00
Source · generatesCommand ClickMe → generatesCommand → ClickMeCommand trace-generated-command · 직접 근거 · confidence 1.00
Source · forwardsTo ControlsDemoRow.ClickMe → forwardsTo → Event.ClickMe trace-forwards-to · 직접 근거 · confidence 1.00
Source · targetMethod ControlsEvent.ClickMe trace-event-target · 직접 근거 · confidence 1.00
검색 원본
서버 저장소 소스 코드
생성 모델
codex-cli:default
생성 정책
dreamine-repository-search-v4
마지막 검증
2026-07-20 23:21:56
이 답변이 유용했나요?