RadioButtons.SelectionChanged 이벤트

정의

현재 선택한 항목이 변경될 때 발생합니다.

이 설명서는 UWP용 WinUI 2에 적용됩니다(Windows 앱 SDKWinUI의 경우 Windows 앱 SDK 네임스페이스 참조).

// Register
event_token SelectionChanged(SelectionChangedEventHandler const& handler) const;

// Revoke with event_token
void SelectionChanged(event_token const* cookie) const;

// Revoke with event_revoker
RadioButtons::SelectionChanged_revoker SelectionChanged(auto_revoke_t, SelectionChangedEventHandler const& handler) const;
public event SelectionChangedEventHandler SelectionChanged;
Public Custom Event SelectionChanged As SelectionChangedEventHandler 

이벤트 유형

예제

이 예제 SelectionChanged 에서는 "ExampleBorder"라는 Border 요소의 배경색을 변경하기 위해 이벤트가 처리됩니다.

<!-- xmlns:muxc="using:Microsoft.UI.Xaml.Controls -->
<muxc:RadioButtons Header="Background color"
                   SelectionChanged="BackgroundColor_SelectionChanged">
    <x:String>Red</x:String>
    <x:String>Green</x:String>
    <x:String>Blue</x:String>
</muxc:RadioButtons>

...

<Border x:Name="ExampleBorder" Width="100" Height="100"/>
// xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (ExampleBorder != null && sender is muxc.RadioButtons rb)
    {
        string colorName = rb.SelectedItem as string;
        switch (colorName)
        {
            case "Red":
                ExampleBorder.Background = new SolidColorBrush(Colors.Red);
                break;
            case "Green":
                ExampleBorder.Background = new SolidColorBrush(Colors.Green);
                break;
            case "Blue":
                ExampleBorder.Background = new SolidColorBrush(Colors.Blue);
                break;
        }
    }
}

설명

자세한 정보, 디자인 지침 및 코드 예제는 라디오 단추를 참조하세요.

SelectionChanged 옵션을 선택할 때 동작을 수행하도록 이벤트를 처리합니다.

컨트롤의 SelectItem 속성 또는 SelectionChangedEventArgs.AddedItems 속성에서 선택한 항목을 가져올 수 있습니다. 이벤트 인수를 사용하는 경우 인덱스 0에서 선택한 항목이 하나만 있으므로 다음과 같이 string colorName = e.AddedItems[0] as string;선택한 항목을 가져올 수 있습니다.

적용 대상

추가 정보