■ ComboBox 클래스에서 우선 순위 필터 콤보 박스를 사용하는 방법을 보여준다.
▶ IAttribute.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
namespace TestProject { /// <summary> /// 어트리뷰트 인터페이스 /// </summary> /// <typeparam name="T">타입</typeparam> public interface IAttribute<T> { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 값 - Value /// <summary> /// 값 /// </summary> T Value { get; } #endregion } } |
▶ DescriptionAttribute.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 58 |
using System; namespace TestProject { /// <summary> /// 설명 어트리뷰트 /// </summary> public class DescriptionAttribute : Attribute, IAttribute<string> { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 설명 /// </summary> private readonly string description; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 값 - Value /// <summary> /// 값 /// </summary> public string Value { get { return this.description; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DescriptionAttribute(description) /// <summary> /// 생성자 /// </summary> /// <param name="description">설명</param> public DescriptionAttribute(string description) { this.description = description; } #endregion } } |
▶ IconURIAttribute.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 58 |
using System; namespace TestProject { /// <summary> /// 아이콘 URI 어트리뷰트 /// </summary> public class IconURIAttribute : Attribute, IAttribute<string> { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 아이콘 URI /// </summary> private readonly string iconURI; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 값 - Value /// <summary> /// 값 /// </summary> public string Value { get { return this.iconURI; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - IconURIAttribute(iconURI) /// <summary> /// 생성자 /// </summary> /// <param name="iconURI">아이콘 URI</param> public IconURIAttribute(string iconURI) { this.iconURI = iconURI; } #endregion } } |
▶ PriorityLevelAttribute.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 58 |
using System; namespace TestProject { /// <summary> /// 우선 순위 레벨 어트리뷰트 /// </summary> public class PriorityLevelAttribute : Attribute, IAttribute<int> { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 우선 순위 레벨 /// </summary> private readonly int priorityLevel; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 값 - Value /// <summary> /// 값 /// </summary> public int Value { get { return this.priorityLevel; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - PriorityLevelAttribute(priorityLevel) /// <summary> /// 생성자 /// </summary> /// <param name="priorityLevel">우선 순위 레벨</param> public PriorityLevelAttribute(int priorityLevel) { this.priorityLevel = priorityLevel; } #endregion } } |
▶ EnumerationExtension.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 |
using System; using System.Reflection; namespace TestProject.Extension { /// <summary> /// 열거형 확장 /// </summary> public static class EnumerationExtension { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 어트리뷰트 값 구하기 - GetAttributeValue<TAttribute, TAttributeValue>(value) /// <summary> /// 어트리뷰트 값 구하기 /// </summary> /// <typeparam name="TAttribute">어트리뷰트 타입</typeparam> /// <typeparam name="TAttributeValue">어트리뷰트 값 타입</typeparam> /// <param name="value">열거형 값</param> /// <returns>어트리뷰트 값</returns> public static TAttributeValue GetAttributeValue<TAttribute, TAttributeValue>(this Enum value) { TAttributeValue attributeValue = default(TAttributeValue); if(value != null) { FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); if(fieldInfo != null) { TAttribute[] attributeArray = fieldInfo.GetCustomAttributes(typeof(TAttribute), false) as TAttribute[]; if(attributeArray != null && attributeArray.Length > 0) { IAttribute<TAttributeValue> attribute = attributeArray[0] as IAttribute<TAttributeValue>; if(attribute != null) { attributeValue = attribute.Value; } } } } return attributeValue; } #endregion } } |
▶ AutoFilterColumn.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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
using System.Collections; using System.ComponentModel; namespace TestProject { /// <summary> /// 자동 필터 컬럼 /// </summary> /// <typeparam name="TItem">항목 타입</typeparam> public class AutoFilterColumn<TItem> : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 이벤트 - PropertyChanged /// <summary> /// 속성 변경시 이벤트 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 값 /// </summary> private object value; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 부모 - Parent /// <summary> /// 부모 /// </summary> public AutoFilterCollection<TItem> Parent { get; set; } #endregion #region 명칭 - Name /// <summary> /// 명칭 /// </summary> public string Name { get; set; } #endregion #region 레벨 - Level /// <summary> /// 레벨 /// </summary> public int? Level { get; set; } #endregion #region 값 - Value /// <summary> /// 값 /// </summary> public object Value { get { return this.value; } set { if(this.value == value) { return; } this.value = value; Parent.NotifyAll(); } } #endregion #region 중복 제거 값 열거 가능형 - DistinctValueEnumerable /// <summary> /// 중복 제거 값 열거 가능형 /// </summary> public IEnumerable DistinctValueEnumerable { get { IEnumerable enumerable = Parent.GetValueEnumerableForFilter(Name); return enumerable; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Internal #region 통지하기 - Notify() /// <summary> /// 통지하기 /// </summary> internal void Notify() { FirePropertyChangedEvent("DistinctValueEnumerable"); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName) /// <summary> /// 속성 변경시 이벤트 발생시키기 /// </summary> /// <param name="propertyName">속성명</param> protected void FirePropertyChangedEvent(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion } } |
▶ AutoFilterCollection.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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; namespace TestProject { /// <summary> /// 자동 필터 컬렉션 /// </summary> /// <typeparam name="TItem">항목 타입</typeparam> public class AutoFilterCollection<TItem> : INotifyPropertyChanged { //////////////////////////////////////////////////////////////////////////////////////////////////// Event ////////////////////////////////////////////////////////////////////////////////////////// Public #region 속성 변경시 이벤트 - PropertyChanged /// <summary> /// 속성 변경시 이벤트 /// </summary> public event PropertyChangedEventHandler PropertyChanged; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 소스 열거 가능형 /// </summary> private IEnumerable<TItem> sourceEnumerable; /// <summary> /// 자동 필터 컬럼 리스트 /// </summary> private readonly List<AutoFilterColumn<TItem>> autoFilterColumnList = new List<AutoFilterColumn<TItem>>(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 소스 열거 가능형 - SourceEnumerable /// <summary> /// 소스 열거 가능형 /// </summary> public IEnumerable<TItem> SourceEnumerable { get { return this.sourceEnumerable; } set { if(this.sourceEnumerable != value) { this.sourceEnumerable = value; Calculate(); } } } #endregion #region 자동 필터 컬럼 리스트 - AutoFilterColumnList /// <summary> /// 자동 필터 컬럼 리스트 /// </summary> public List<AutoFilterColumn<TItem>> AutoFilterColumnList { get { return this.autoFilterColumnList; } } #endregion #region 필터 열거 가능형 - FilteredEnumerable /// <summary> /// 필터 열거 가능형 /// </summary> public IEnumerable<TItem> FilteredEnumerable { get { IEnumerable<TItem> resultEnumerable = SourceEnumerable; foreach(AutoFilterColumn<TItem> autoFilterColumn in AutoFilterColumnList) { if(autoFilterColumn.Value == null || autoFilterColumn.Value.Equals("All")) { continue; } PropertyInfo propertyInfo = typeof(TItem).GetProperty(autoFilterColumn.Name); resultEnumerable = resultEnumerable.Where(x => propertyInfo.GetValue(x, null).Equals(autoFilterColumn.Value)); } return resultEnumerable; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Internal #region 모두 통지하기 - NotifyAll() /// <summary> /// 모두 통지하기 /// </summary> internal void NotifyAll() { foreach(AutoFilterColumn<TItem> autoFilterColumn in AutoFilterColumnList) { autoFilterColumn.Notify(); } FirePropertyChangedEvent("FilteredEnumerable"); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Public #region 필터용 값 열거 가능형 구하기 - GetValueEnumerableForFilter(columnName) /// <summary> /// 필터용 값 열거 가능형 구하기 /// </summary> /// <param name="columnName">컬럼명</param> /// <returns>필터용 값 열거 가능형</returns> public IEnumerable GetValueEnumerableForFilter(string columnName) { IEnumerable<TItem> resultEnumerable = SourceEnumerable; foreach(AutoFilterColumn<TItem> autoFilterColumn in AutoFilterColumnList) { if(autoFilterColumn.Name == columnName) { continue; } if(autoFilterColumn.Value == null || autoFilterColumn.Value.Equals("All")) { continue; } PropertyInfo autoFilterColumnPropertyInfo = typeof(TItem).GetProperty(autoFilterColumn.Name); if(autoFilterColumn.Level == null || AutoFilterColumnList.FirstOrDefault(x => x.Name == columnName).Level >= autoFilterColumn.Level) { resultEnumerable = resultEnumerable.Where(x => autoFilterColumnPropertyInfo.GetValue(x, null).Equals(autoFilterColumn.Value)); } } PropertyInfo propertyInfo = typeof(TItem).GetProperty(columnName); List<object> propertyValueList = resultEnumerable.Select(x => propertyInfo.GetValue(x, null)).Concat(new List<object>()).ToList(); propertyValueList.Sort(); return propertyValueList.Distinct(); } #endregion #region 자동 필터 컬럼 구하기 - GetAutoFilterColumn(columnName) /// <summary> /// 자동 필터 컬럼 구하기 /// </summary> /// <param name="columnName">컬럼명</param> /// <returns>자동 필터 컬럼</returns> public AutoFilterColumn<TItem> GetAutoFilterColumn(string columnName) { return AutoFilterColumnList.SingleOrDefault(x => x.Name == columnName); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName) /// <summary> /// 속성 변경시 이벤트 발생시키기 /// </summary> /// <param name="propertyName">속성명</param> protected void FirePropertyChangedEvent(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private #region 계산하기 - Calculate() /// <summary> /// 계산하기 /// </summary> private void Calculate() { PropertyInfo[] propertyInfoArray = typeof(TItem).GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach(PropertyInfo propertyInfo in propertyInfoArray) { int? priorityLevel = null; object[] attributeArray = propertyInfo.GetCustomAttributes(typeof(Attribute), true); if(attributeArray != null && attributeArray.Length > 0) { PriorityLevelAttribute priorityLevelAttribute = attributeArray[0] as PriorityLevelAttribute; if(priorityLevelAttribute != null) { priorityLevel = priorityLevelAttribute.Value; } } AutoFilterColumnList.Add ( new AutoFilterColumn<TItem> { Parent = this, Level = priorityLevel, Name = propertyInfo.Name, Value = null } ); } } #endregion } } |
▶ League.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 |
namespace TestProject { /// <summary> /// 리그 /// </summary> public enum League { /// <summary> /// 아르헨티나 프리메라 디비전 /// </summary> [IconURI("pack://application:,,,/TestProject;component/IMAGE/Argentina.png")] [Description("아르헨티나 프리메라 디비전")] PrimeraDivision = 1, /// <summary> /// 영국 프리미어 리그 /// </summary> [IconURI("pack://application:,,,/TestProject;component/IMAGE/England.png")] [Description("영국 프리미어 리그")] PremierLeague = 2, /// <summary> /// 스페인 라 리가 /// </summary> [IconURI("pack://application:,,,/TestProject;component/IMAGE/Spain.png")] [Description("스페인 라 리가")] LaLiga = 3 } } |
▶ Football.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 58 59 60 61 62 63 |
namespace TestProject { /// <summary> /// 축구 /// </summary> public class Football { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 리그 - League /// <summary> /// 리그 /// </summary> [PriorityLevel(1)] public League League { get; set; } #endregion #region 팀 - Team /// <summary> /// 팀 /// </summary> [PriorityLevel(2)] public string Team { get; set; } #endregion #region 선수 수 - PlayerCount /// <summary> /// 선수 수 /// </summary> public int PlayerCount { get; set; } #endregion #region 선수명 - PlayerName /// <summary> /// 선수명 /// </summary> public string PlayerName { get; set; } #endregion #region 선수 - Player /// <summary> /// 선수 /// </summary> [PriorityLevel(3)] public string Player { get { return string.Format("{0} - {1}", PlayerCount, PlayerName); } } #endregion } } |
▶ FootballCollection.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using System.Collections.Generic; namespace TestProject { /// <summary> /// 축구 컬렉션 /// </summary> public class FootballCollection : List<Football> { } } |
▶ FootballAutoFilterCollection.cs
1 2 3 4 5 6 7 8 9 10 11 |
namespace TestProject { /// <summary> /// 축구 자동 필터 컬렉션 /// </summary> public class FootballAutoFilterCollection : AutoFilterCollection<Football> { } } |
▶ DataHelper.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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
namespace TestProject { /// <summary> /// 데이터 헬퍼 /// </summary> public class DataHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 축구 컬렉션 구하기 - GetFootballCollection() /// <summary> /// 축구 컬렉션 구하기 /// </summary> /// <returns>축구 컬렉션</returns> public static FootballCollection GetFootballCollection() { FootballCollection collection = new FootballCollection { new Football { League = League.PremierLeague, Team = "Manchester United", PlayerCount = 9, PlayerName = "Cristiano Ronaldo" }, new Football { League = League.PremierLeague, Team = "Manchester United", PlayerCount = 18, PlayerName = "Mikael Silvestre" }, new Football { League = League.PremierLeague, Team = "Arsenal", PlayerCount = 18, PlayerName = "Mikael Silvestre" }, new Football { League = League.LaLiga, Team = "Real Madrid", PlayerCount = 9, PlayerName = "Cristiano Ronaldo" }, new Football { League = League.LaLiga, Team = "Real Madrid", PlayerCount = 20, PlayerName = "Gonzalo Higuain" }, new Football { League = League.LaLiga, Team = "Racing", PlayerCount = 24, PlayerName = "Luis Garcia" }, new Football { League = League.PrimeraDivision, Team = "Arsenal", PlayerCount = 6, PlayerName = "Anibal Matellan" }, new Football { League = League.PrimeraDivision, Team = "Racing", PlayerCount = 16, PlayerName = "Pablo Caballero" }, new Football { League = League.PrimeraDivision, Team = "River Plate", PlayerCount = 20, PlayerName = "Gonzalo Higuain" }, }; return collection; } #endregion } } |
▶ LeagueIconURIConverter.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 58 59 60 61 |
using System; using System.Globalization; using System.Windows.Data; using TestProject.Extension; namespace TestProject { /// <summary> /// 리그→아이콘 URI 변환자 /// </summary> public class LeagueIconURIConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { if(sourceValue != null) { League league = sourceValue is League ? (League)sourceValue : League.PremierLeague; string leagueIconURI = league.GetAttributeValue<IconURIAttribute, string>(); return leagueIconURI; } return null; } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { return null; } #endregion } } |
▶ LeagueNameConverter.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 58 59 60 61 |
using System; using System.Globalization; using System.Windows.Data; using TestProject.Extension; namespace TestProject { /// <summary> /// 리그→리그명 변환자 /// </summary> public class LeagueNameConverter : IValueConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 변환하기 - Convert(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>변환 값</returns> public object Convert(object sourceValue, Type targetType, object parameter, CultureInfo cultureInfo) { if(sourceValue != null) { League league = sourceValue is League ? (League) sourceValue : League.PremierLeague; string description = league.GetAttributeValue<DescriptionAttribute, string>(); return description; } return null; } #endregion #region 역변환하기 - ConvertBack(sourceValue, targetType, parameter, cultureInfo) /// <summary> /// 역변환하기 /// </summary> /// <param name="sourceValue">소스 값</param> /// <param name="targetType">타겟 타입</param> /// <param name="parameter">매개 변수</param> /// <param name="cultureInfo">문화 정보</param> /// <returns>역변환 값</returns> public object ConvertBack(object sourceValue, Type targetType, object parameter, CultureInfo culture) { return null; } #endregion } } |
▶ 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="ComboBox 클래스 : 우선 순위 필터 콤보 박스 사용하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <local:LeagueNameConverter x:Key="LeagueNameConverterKey" /> <local:LeagueIconURIConverter x:Key="LeagueIconURIConverterKey" /> </Window.Resources> <Grid HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Label Grid.Row="0" Content="리그" /> <ComboBox Grid.Row="1" Width="300" Height="25" DataContext="{Binding Path=LeagueColumn}" ItemsSource="{Binding DistinctValueEnumerable}" SelectedItem="{Binding Value}"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Image Margin="4 0 4 0" Width="16" Height="16" Source="{Binding Converter={StaticResource LeagueIconURIConverterKey}}" /> <TextBlock Text="{Binding Converter={StaticResource LeagueNameConverterKey}}" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> <Label Grid.Row="2" Margin="0 10 0 0" Content="팀" /> <ComboBox Grid.Row="3" Width="300" Height="25" DataContext="{Binding Path=TeamColumn}" ItemsSource="{Binding DistinctValueEnumerable}" SelectedItem="{Binding Value}" /> <Label Grid.Row="4" Margin="0 10 0 0" Content="선수" /> <ComboBox Grid.Row="5" Width="300" Height="25" DataContext="{Binding Path=PlayerColumn}" ItemsSource="{Binding DistinctValueEnumerable}" SelectedItem="{Binding Value}" /> </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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 축구 자동 필터 컬렉션 /// </summary> private readonly FootballAutoFilterCollection footballAutoFilterCollection = new FootballAutoFilterCollection(); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 리그 컬럼 - LeagueColumn /// <summary> /// 리그 컬럼 /// </summary> public AutoFilterColumn<Football> LeagueColumn { get { return this.footballAutoFilterCollection.AutoFilterColumnList[0]; } } #endregion #region 팀 컬럼 - TeamColumn /// <summary> /// 팀 컬럼 /// </summary> public AutoFilterColumn<Football> TeamColumn { get { return this.footballAutoFilterCollection.AutoFilterColumnList[1]; } } #endregion #region 선수 컬럼 - PlayerColumn /// <summary> /// 선수 컬럼 /// </summary> public AutoFilterColumn<Football> PlayerColumn { get { return this.footballAutoFilterCollection.AutoFilterColumnList[4]; } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.footballAutoFilterCollection.SourceEnumerable = DataHelper.GetFootballCollection(); DataContext = this; } #endregion } } |