! 제품 버전을 정확하게 입력해 주세요.
제품 버전이 정확하게 기재되어 있지 않은 경우,
최신 버전을 기준으로 안내 드리므로
더욱 빠르고 명확한 안내를 위해
제품 버전을 정확하게 입력해 주세요!

WinForms 응용 프로그램에 WPF 사용자 컨트롤 추가 > 온라인 스터디

본문 바로가기

ComponentOne

온라인 스터디

Winforms윈폼 WinForms 응용 프로그램에 WPF 사용자 컨트롤 추가

페이지 정보

작성자 GrapeCity 작성일 2023-02-22 14:59 조회 646회 댓글 0건

본문

첨부파일

WinForms와 WPF는 두 개의 다른 기술로, 각각 장단점이 있습니다.


하지만 두 가지 기술의 UI 컨트롤을 섞을 수 있으므로 WinForms 응용 프로그램에서 WPF 컨트롤을 추가하여 단일 응용 프로그램에서 WinForms 및 WPF의 기능을 지원할 수 있습니다.


WinForms 응용 프로그램에서 MVVM 접근법과 WPF의 Binding 기능을 지원할 수도 있습니다.


이 요구 사항을 달성하려면 WinForms 응용 프로그램에서 WPF UserControl을 호스팅해야 합니다.


이 블로그에서는 WinForms 응용 프로그램에서 ComponentOne WPF 컨트롤(C1FlexGrid 및 C1Rating)을 사용하는 방법을 살펴봅니다.



Winforms에서 WPF UserControl을 호스팅하는 단계


ElementHost 컨트롤 추가


ElementHost는 WPF(Windows Presentation Foundation) 요소를 호스팅하는 데 사용할 수 있는 WinForms 컨트롤입니다.


Windows Form에서 ElementHost 컨트롤을 추가하려면 WindowsFormsIntegration.dll 참조 목록을 추가해야 합니다.

그러면 도구 상자에서 ElementHost를 끌어서 Form에 놓을 수 있습니다.



WPF UserControl 만들기


WinForms 응용 프로그램에서 WPF UserControl을 만들 수 있습니다.


프로젝트의 Solution Explorer에서 프로젝트 노드를 마우스 오른쪽 버튼으로 클릭하고 추가->새 항목을 선택합니다. UserControl(WPF)을 선택하고 "WpfUserControl.xaml"이라는 자체 UserControl을 만듭니다.




WPF UserControl 편집


일부 XAML 코드를 사용하여 WPF UserControl을 편집할 수 있습니다.

C1FlexGrid(WPF) 및 C1Rating과 같은 WPF 컨트롤을 WPF UserControl에 추가할 수 있습니다.

<UserControl
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:local="clr-namespace:WpfControlHost"
            xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" x:Class="WpfControlHost.WpfUserControl"
            mc:Ignorable="d"
            d:DesignHeight="200" d:DesignWidth="500">
   <UserControl.DataContext>
       <local:ViewModel/>
   </UserControl.DataContext>
   <Grid>
   
   <!--C1 WPF FlexGrid control-->
       <c1:C1FlexGrid x:Name="grid" ItemsSource="{Binding Songs}" MinRowHeight="50" Loaded="FlexgridLoaded" AutoGenerateColumns="False">
           <c1:C1FlexGrid.Columns>
               <c1:Column Header="Track" Binding="{Binding Track}"/>
               <c1:Column Header="Duration" Binding="{Binding Duration}"/>
               <c1:Column Header="Size" Binding="{Binding Size}"/>
               <c1:Column Header="Rating" Binding="{Binding Rating}">
                   <c1:Column.CellTemplate>
                       <DataTemplate>
                           <!--C1 WPF C1Rating control-->
                           <c1:C1Rating Value="{Binding Rating}" RatedBrush="Yellow" HoveredBrush="Orange" VerticalAlignment="Center" ShowToolTip="False">
                           </c1:C1Rating>
                       </DataTemplate>
                   </c1:Column.CellTemplate>
               </c1:Column>
           </c1:C1FlexGrid.Columns>
       </c1:C1FlexGrid>
   </Grid>
</UserControl>
​


ElementHost에서 WPF UserControl 호스팅


마지막으로 ElementHost에서 WPF UserControl을 호스팅합니다.

먼저 솔루션을 다시 빌드하면 WpfUserControl이 도구 상자에 표시됩니다.


이제 도구 상자를 열고 WpfUserControl을 도구 상자에서 끌어다 양식에 배치합니다.


마지막으로 WPF 컨트롤(C1FlexGrid and C1Rating)이 호스팅한 WPF UserControl에 추가된 WinForms 응용 프로그램에서 호스팅됩니다.


전체 구현을 위해 샘플을 다운로드합니다. (또는 첨부파일 참고)





지금 바로 ComponentOne을 다운로드하여 직접 테스트해보세요!

 
  • 페이스북으로 공유
  • 트위터로  공유
  • 링크 복사
  • 카카오톡으로 보내기

댓글목록

등록된 댓글이 없습니다.

메시어스 홈페이지를 통해 제품에 대해서 더 자세히 알아 보세요!
홈페이지 바로가기

태그1

메시어스 홈페이지를 통해 제품에 대해서 더 자세히 알아 보세요!
홈페이지 바로가기
이메일 : sales-kor@mescius.com | 전화 : 1670-0583 | 경기도 과천시 과천대로 7길 33, 디테크타워 B동 1107호 메시어스(주) 대표자 : 허경명 | 사업자등록번호 : 123-84-00981 | 통신판매업신고번호 : 2013-경기안양-00331 ⓒ 2024 MESCIUS inc. All rights reserved.