김형준 GIS 연구소 (for Developers)  
Front Page
Notice | E-Mail | Admin | Write Article   
 
2007/04/30 01:23 2007/04/30 01:23
Non-Rectangle Window in WPF
오늘 작성해본 WPF에서 직사각형이 아닌 창을 나타내는 코드이다. UI 부분이므로 모든 주요 코드는 XAML에서 작성되며 드레그했을시에 창이 이동되는 이벤트 처리는 Behind Code(.CS 파일)에서 작성하였다. 먼저 XAML 코드는 아래와 같다.

<Window 
  x:Class="NonRectangularWindowSample.NonRectangularWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Kim Hyoung Jun" 
  MouseLeftButtonDown="eventMouseLeftButtonDown"
  WindowStyle="None" 
  AllowsTransparency="True" 
  Background="Transparent">
  <Canvas Width="200" Height="100" >
    <Path Stroke="LightBlue" StrokeThickness="2">
      <Path.Fill>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
          <GradientStop Color="White" Offset="0" />
          <GradientStop Color="White" Offset="0.2" />
          <GradientStop Color="LightBlue" Offset="0.9" />
          <GradientStop Color="Black" Offset="1" />
        </LinearGradientBrush>
      </Path.Fill>

      <Path.Data>
        <PathGeometry>
          <PathFigure StartPoint="40,20" IsClosed="True">
            <LineSegment Point="160,20" />
            <ArcSegment Point="180,40" Size="20,20" 
                        SweepDirection="Clockwise" />
            <LineSegment Point="180,80" />
            <ArcSegment Point="160,100" Size="20,20" 
                        SweepDirection="Clockwise" />
            <LineSegment Point="40,100" />
            <ArcSegment Point="20,80" Size="20,20" 
                        SweepDirection="Clockwise" />
            <LineSegment Point="20,40" />
            <ArcSegment Point="40,20" Size="20,20" 
                        SweepDirection="Clockwise" />
          </PathFigure>
        </PathGeometry>
      </Path.Data>
    </Path>

    <Label Width="200"
           Height="120"
           FontSize="15"
           HorizontalContentAlignment="Center"
           VerticalContentAlignment="Center"
           Content="끌면 이동됩니다" />
  </Canvas>
</Window>
창을 원하는 모양으로 만들기 위해서 반드시 설정해야할 Window의 속성은 위의 코드에서 분홍색으로 나타낸 WindowStyle, AllowTransparency, Background 속성이다. 그리고 Path Element를 이용해 원하는 모양을 그려주면 끝이다. 참으로 간단하면서도 명확하다. 실행 결과는 다음과 같다.

드레그를 하면 창이 이동을 하는데 그와 관련된 코드는 다음과 같다. 마우스의 왼쪽 버턴을 눌렸을 경우 발생하는 이벤트이다.

void eventMouseLeftButtonDown(object sender, 
                              MouseButtonEventArgs e) {
     DragMove();
}
Tag :
Track this back : http://www.gisdeveloper.co.kr/trackback/232
Commented by jsharp at 2008/01/24 22:02  r x
너무 잘 보고 있습니다. 감사합니다.
Commented by 김형준 at 2008/01/25 12:11  r x
네~ ^^, 잘보셨다니 좋군요~
Commented by everbleu at 2008/05/23 17:24  r x
고맙습니다. 도움이 많이 됩니다.
윈도우에 대해 알파블랜딩 처리하는 방법도 위와 같이 쉽게 되나요?
Commented by Dip2K at 2008/05/24 00:34  r x
WPF의 윈도우가 아닌 일반 윈도우를 말씀하시는거라면, 알파블랜딩을 해주는 Win32 API가 따로 있습니다. 물론 쉽게 되구요~
Commented by everbleu at 2008/05/27 02:47  r x
WPF의 윈도우에서 알파블랜딩이 가능한지 알고 싶어요.
Win32로 알파블랜딩 처리는 가능하지만, WPF 윈도우를 MFC에서 사용한다면.. WPF에서 알파블랜딩 처리까지 해주면 깔끔하게 개발할 수 있을 듯 합니다.
Commented by Dip2K at 2008/05/28 09:25  r x
위의 내용은 알파블랜딩이라기 보다는 윈도우 전체를 투명으로 설정하고 윈도우에 놓인 내용물만을 보이게 하는 것입니다. MFC 폼 위에 WPF 컨트롤을 올릴수있는 글을 봤는데, 위의 글과 적절하게 조합을 하면 원하시는 결과를 얻으실수있을것같습니다~

name    password    homepage
 hidden
BLOG main image
 Notice
DuraMap-Xr 소개 및 다운로드
[오픈소스] SimpleSHP v0.1
FingerEyes-Xr 소개 및 다운로드
OpenGL Tutorials
 Category
전체 (531)
GIS 개발 (146)
프로그래밍 (233)
스치는 생각들 (129)
번역 또는 집필 (3)
 TAGS
GIS Xr OpenGL Shader FingerEyes BlackPoint Algorithm Java Map Engine WPF
 Calendar
«   2012/02   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29      
 Recent Entries
[FingerEyes] 지오메트리...
[FingerEyes] Geometry로...
[FingerEyes] FID 리스트...
[FingerEyes] UPDATE, INS...
영화, "부러진 화살"
 Recent Comments
소스코드 그대로 써보아도...
인현환 - 13:50
글의 예제 코드의 숫자들...
김형준 - 12:57
안녕하세요. 포스트 잘 보...
인현환 - 11:15
메일로 답변드렸습니다....
김형준 - 02/01
txt파일을 엑셀로 변환하...
최상준 - 02/01
코봉히님두 새해 복 많이...
김형준 - 01/25
아 너무 감사합니다. 새해...
코봉히 - 01/23
wkb는 http://www.gisdeve...
김형준(Dip2K) - 01/23
wkb의 구조가 shp파일의...
코봉히 - 01/20
wkb는 바이너리인지라.....
김형준(Dip2K) - 01/20
 Archive
2012/02
2012/01
2011/12
2011/11
2011/10
2011/09
2011/08
2011/07
2011/06
2011/05
2011/04
2011/03
 Link Site
Adobe Flex 3 Help
Cartograph 2.0
GADM
GIS 위키디피아
GIS 프로그래밍 연구소
MapTools.org
OGC
OGRE3D
OSGeo 한국 지부
Paul Bourke Site
Wikipedia
국가수자원관리 정보시스템
국립지리원
국토연구원
국토해양부
네이버 과학
대한측량협회
류광님의 블로그
이민파님의 공간분석과 리...
지오서비스(GeoService)
 Visitor Statistics
Total : 929879
Today : 530
Yesterday : 511
태터툴즈 배너
rss