ComboBox 컨트롤 (여러개의 항목 중 하나를 선택 가능)
[MainPage.xaml]
<UserControl x:Class="RiaComboBox.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock Text="인코딩"></TextBlock>
<ComboBox x:Name="enc" SelectedIndex="0">
<ComboBox.Items>
<ComboBoxItem Content="Text" />
<ComboBoxItem Content="HTML" />
<ComboBoxItem Content="Mixed" />
</ComboBox.Items>
</ComboBox>
<Button x:Name="btnSelect" Content="선택" />
<TextBlock x:Name="lbl" />
</StackPanel>
</Grid>
</UserControl>
[MainPage.xaml.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace RiaComboBox
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
btnSelect.Click += new RoutedEventHandler(btnSelect_Click);
}
void btnSelect_Click(object sender, RoutedEventArgs e)
{
//lbl.Text = enc.SelectedItem.ToString(); // 선택된 항목을 출력
ComboBox cb = this.enc as ComboBox;
ListBoxItem lbi = cb.SelectedItem as ListBoxItem; // 선택된 항목 한개를 가져오기
lbl.Text = lbi.Content.ToString(); // Content의 값을 문자열로 : Text, HTML, Mixed
}
}
}