■ Chip 엘리먼트를 사용하는 방법을 보여준다.
▶ MainApplication.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<Application x:Class="TestProject.MainApplication" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <materialDesign:BundledTheme BaseTheme="Inherit" PrimaryColor="DeepPurple" SecondaryColor="Lime" ColorAdjustment="{materialDesign:ColorAdjustment}" /> <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> |
▶ MainWindow.xaml
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" Width="800" Height="600" Title="Chip 엘리먼트 사용하기" Background="{DynamicResource MaterialDesignPaper}" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <Style TargetType="materialDesign:Chip"> <Setter Property="Margin" Value="10" /> </Style> </Window.Resources> <Grid> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel Orientation="Horizontal"> <materialDesign:Chip Content="James Willock"> <materialDesign:Chip.Icon> <Image Source="IMAGE/sample.jpg" /> </materialDesign:Chip.Icon> </materialDesign:Chip> <materialDesign:Chip Content="Example Chip" /> <materialDesign:Chip Content="ANZ Bank" Icon="A" /> <materialDesign:Chip Content="ZNA Inc" Icon="Z" /> <materialDesign:Chip IconBackground="{DynamicResource PrimaryHueDarkBrush}" IconForeground="{DynamicResource PrimaryHueDarkForegroundBrush}" Content="Twitter"> <materialDesign:Chip.Icon> <materialDesign:PackIcon Kind="Twitter" /> </materialDesign:Chip.Icon> </materialDesign:Chip> </StackPanel> <StackPanel Orientation="Horizontal"> <materialDesign:Chip IsDeletable="True" ToolTip="Just a tool tip" DeleteToolTip="Your friendly neighbor delete button" Content="James Willock" Click="chip_Click" DeleteClick="chip_DeleteClick"> <materialDesign:Chip.Icon> <Image Source="IMAGE/sample.jpg" /> </materialDesign:Chip.Icon> </materialDesign:Chip> <materialDesign:Chip IsDeletable="True" ToolTip="This is an example chip" Content="Example Chip" /> <materialDesign:Chip Icon="A" IsDeletable="True" Content="ANZ Bank" /> <materialDesign:Chip IconBackground="{DynamicResource PrimaryHueLightBrush}" IconForeground="{DynamicResource PrimaryHueLightForegroundBrush}" Icon="Z" IsDeletable="True" Content="ZNA Inc" /> </StackPanel> </StackPanel> </Grid> </Window> |
▶ MainWindow.xaml.cs
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System.Windows; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 칩 클릭시 처리하기 - chip_Click(sender, e) /// <summary> /// 칩 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void chip_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Chip Clicked!"); } #endregion #region 칩 삭제 버튼 클릭시 처리하기 - chip_DeleteClick(sender, e) /// <summary> /// 칩 삭제 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void chip_DeleteClick(object sender, RoutedEventArgs e) { MessageBox.Show("Chip delete button Clicked!"); } #endregion } } |