[WPF] 공공데이터 포털 API 이용 클라이언트 구현 Part 3

이미지
그룹핑 ListViewItem 그룹핑 할 수 있습니다. 먼저 CheckBox에 Checked 이벤트를 통해 그룹핑을 추가하고 RemoveChecked 이벤트를 통해 그룹핑을 제거 할 수 있도록 CheckBox를 선언 합니다. 1: <!-- Group CheckBox --> 2: <CheckBox Grid.Column="0" 3: Grid.Row="0" 4: Checked="AddGrouping" 5: Unchecked="RemoveGrouping">Group by Name</CheckBox> 그룹 스타일 선언 GroupStyle 속성에 ContainerStyle 속성을 이용해 Style을 지정 합니다. Expander 컨트롤을 이용해 아파트명과 그룹 아이템의 개수를 Expander Header에 표시 하도록 ControlTemlate를 선언 합니다. 1: <!-- Group Style --> 2: <ListView.GroupStyle> 3: <GroupStyle> 4: <GroupStyle.ContainerStyle> 5: <Style TargetType="{x:Type GroupItem}"> 6: <Setter Property="Margin" Value="0,0,0,5" /> 7: <Setter Property="Te...

MSDN WPF 샘플 따라하기 - SearchingForElement

SearchingForElement

이 예제에서는 요소를 검색하는 방법을 설명합니다.

시나리오:
  • StackPanel의 자식 요소를 검색하여 찾은 요소의 색을 변경 합니다.

창 구성

요소를 찾는 이벤트가 설정 된 Button과 3개의 자식을 가지는 StackPanel을 선언 하고, Button, TextBlock 요소에 적용하는 Style을 Resources에 선언 합니다.

1:  <Window x:Class="SearchingForElement.MainWindow"  
2:      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
3:      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
4:      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
5:      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
6:      xmlns:local="clr-namespace:SearchingForElement"  
7:      mc:Ignorable="d"  
8:      Title="MainWindow" Height="350" Width="525">  
9:    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">  
10:      <StackPanel.Resources>  
11:        <Style TargetType="{x:Type Button}">  
12:          <Setter Property="Height" Value="20"/>  
13:          <Setter Property="Width" Value="250"/>  
14:          <Setter Property="HorizontalAlignment" Value="Left"/>  
15:        </Style>  
16:        <Style TargetType="{x:Type TextBlock}">  
17:          <Setter Property="HorizontalAlignment" Value="Left"/>  
18:          <Setter Property="FontSize" Value="12"/>  
19:        </Style>  
20:      </StackPanel.Resources>  
21:      <Button Click="Find">Find element with the ID "dog" and change color</Button>  
22:      <StackPanel Name="stackPanel">  
23:        <TextBlock Name="cat">Cat</TextBlock>  
24:        <TextBlock Name="dog">Dog</TextBlock>  
25:        <TextBlock Name="fish">Fish</TextBlock>  
26:      </StackPanel>  
27:    </StackPanel>  
28:  </Window>  

요소 찾기

1:    public partial class MainWindow : Window  
2:    {  
3:      public MainWindow()  
4:      {  
5:        InitializeComponent();  
6:      }  
7:      private void Find(object sender, RoutedEventArgs e)  
8:      {  
9:        var wantedNode = stackPanel.FindName("dog");  
10:        if (wantedNode is TextBlock)  
11:        {  
12:          var wantedChild = wantedNode as TextBlock;  
13:          wantedChild.Foreground = Brushes.Blue;  
14:        }  
15:      }  
16:    }  

댓글

이 블로그의 인기 게시물

[C#] Task 완료 시 다른 Task를 자동으로 수행

[C#] 태스크(Task)가 완료될 때 까지 대기하여 결과를 얻는 방법

[C#] 명시적으로 Task 생성 및 실행