반응형

1. xaml 소스 코드

   - expander는 아래로 촤라락 나오는 아이템 컨트로

 <Window x:Class="_20190410.MainWindow"

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"

xmlns:local="clr-namespace:_20190410"

mc:Ignorable="d"

Title="MainWindow" Height="450" Width="800">

<Grid>

<Grid.ColumnDefinitions>

<ColumnDefinition/>

<ColumnDefinition/>

</Grid.ColumnDefinitions>

 

<ListBox x:Name="lstBox1"

Grid.Column="0" SelectionChanged="lstBox1_SelectionChanged">

<ListBoxItem>One</ListBoxItem>

<ListBoxItem>Two</ListBoxItem>

<ListBoxItem>Three</ListBoxItem>

<ListBoxItem>Four</ListBoxItem>

</ListBox>

 

<ListBox x:Name="lstBox2"

Grid.Column="1" SelectionChanged="lstBox2_SelectionChanged">

<ListBoxItem>One</ListBoxItem>

<Button Content="Two"></Button>

<CheckBox Content="Three"></CheckBox>

<Expander Header="Colors">

<StackPanel>

<RadioButton Content="Red"/>

<RadioButton Content="Green"/>

<RadioButton Content="Blue"/>

</StackPanel>

</Expander>

</ListBox>

</Grid>

</Window>

 

 

2. 이벤트 함수 소스 코드

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

 

namespace _20190410

{

/// <summary>

/// MainWindow.xaml에 대한 상호 작용 논리

/// </summary>

public partial class MainWindow : Window

{

public MainWindow()

{

InitializeComponent();

}

 

private void lstBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

int selectedIndex = lstBox1.SelectedIndex; // 반환형 int

object selecteditem = lstBox1.SelectedItem; //반환형 object

 

MessageBox.Show(selectedIndex.ToString() + "Index : " + selecteditem.ToString());

}

 

private void lstBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

int selectedIndex2 = lstBox2.SelectedIndex; // 반환형 int

object selecteditem2 = lstBox2.SelectedItem; //반환형 object

 

MessageBox.Show(selectedIndex2.ToString() + "Index : " + selecteditem2.ToString());

}

}

}

 

3. 결과

 

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기