Silverlight

60.SilverLight3 - ComboBox

Godffs 2009. 12. 2. 14:01
반응형
ComboBox
- 여러개의 항목중에서 하나를 선택하여 표시하는 컨트롤입니다. ( 데이터 바인딩 가능 )

MainPage.xaml

[그림 60-1]


<Grid x:Name="LayoutRoot" Background="White">

        <StackPanel>

            <!-- -->

            <TextBlock Text=""></TextBlock>

            <ComboBox x:Name="cboSelect" SelectedIndex="0">

                <ComboBox.Items>

                    <ComboBoxItem Content="C#"></ComboBoxItem>

                    <ComboBoxItem Content="ASP.NET"></ComboBoxItem>

                    <ComboBoxItem Content="SilverLight"></ComboBoxItem>

                   

                    <!-- -->

                    <StackPanel>

                        <TextBlock Text=" "></TextBlock>

                        <Image Source="Godffs.jpg" Width="100" Height="150">

                        </Image>                       

                        <Button Content=""></Button>

                    </StackPanel>

                </ComboBox.Items>

            </ComboBox>

            <Button x:Name="btnSelect" Content=""></Button>

            <TextBlock x:Name="lblSelect"></TextBlock>           

        </StackPanel>

</Grid>


MainPage.xaml.cs

namespace ComboBox

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            btnSelect.Click += new RoutedEventHandler(btnSelect_Click);

        }

 

        void btnSelect_Click(object sender, RoutedEventArgs e)

        {

            //Content . (, ,, 용)


            // TextBlock() .

            //lbl.Text = enc.SelectedItem.ToString();

 

            System.Windows.Controls.ComboBox cbo =

                                    this.cboSelect as System.Windows.Controls.ComboBox;

            ListBoxItem lbl = cbo.SelectedItem as ListBoxItem;

           

            try

            {

                lblSelect.Text = lbl.Content.ToString();

            }

 

            catch(Exception)

            {

                lblSelect.Text = ", , ...;;;";

            }

        }

    }

}


결과화면

[그림 60-2]

[그림 60-3]



반응형