WPF에서 열거 형을 콤보 상자 컨트롤에 바인딩하는 방법은 무엇입니까?
열거 형이 그대로 표시되는 간단한 예를 찾으려고합니다. 내가 본 모든 예제는 멋진 표시 문자열을 추가하려고 시도하지만 그 복잡성을 원하지 않습니다.
기본적으로 DataContext를이 클래스로 설정 한 다음 xaml 파일에서 이와 같은 바인딩을 지정하여 바인딩하는 모든 속성을 보유하는 클래스가 있습니다.
<ComboBox ItemsSource="{Binding Path=EffectStyle}"/>
그러나 이것은 ComboBox
as 항목 에 열거 형 값을 표시하지 않습니다 .
Loaded
예를 들어, Window 이벤트 핸들러 에 다음 코드를 배치하여 코드에서 수행 할 수 있습니다 .
yourComboBox.ItemsSource = Enum.GetValues(typeof(EffectStyle)).Cast<EffectStyle>();
XAML에서 바인딩해야하는 경우 ObjectDataProvider
바인딩 소스로 사용 가능한 개체를 만드는 데 사용해야 합니다.
<Window x:Class="YourNamespace.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:StyleAlias="clr-namespace:Motion.VideoEffects">
<Window.Resources>
<ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="StyleAlias:EffectStyle"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<ComboBox ItemsSource="{Binding Source={StaticResource dataFromEnum}}"
SelectedItem="{Binding Path=CurrentEffectStyle}" />
</Grid>
</Window>
다음 코드에주의를 기울이십시오.
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:StyleAlias="clr-namespace:Motion.VideoEffects"
MSDN에서 읽을 수있는 네임 스페이스 및 어셈블리를 매핑하는 방법에 대해 설명합니다 .
바인딩하는 모든 객체가 my에 정의되기를 원 ViewModel
하므로 <ObjectDataProvider>
가능한 경우 xaml에서 사용하지 않으려 고 합니다.
내 솔루션은 View에 정의 된 데이터와 코드 숨김을 사용하지 않습니다. DataBinding, 재사용 가능한 ValueConverter, 모든 Enum 유형에 대한 설명 모음을 가져 오는 메소드 및 바인딩 할 ViewModel의 단일 특성 만 있습니다.
내가 바인딩 할 때 Enum
A와 ComboBox
내가 표시 할 텍스트 결코의 값과 일치하지 Enum
내가 사용하므로, [Description()]
그것을 내가 실제로에 표시하려는 텍스트를 제공하는 속성을 ComboBox
. 내가 요일을 열거하면 다음과 같이 보일 것입니다.
public enum DayOfWeek
{
// add an optional blank value for default/no selection
[Description("")]
NOT_SET = 0,
[Description("Sunday")]
SUNDAY,
[Description("Monday")]
MONDAY,
...
}
먼저 열거 형을 처리하는 몇 가지 방법으로 도우미 클래스를 만들었습니다. 한 방법은 특정 값에 대한 설명을 가져오고 다른 방법은 유형에 대한 모든 값과 설명을 가져옵니다.
public static class EnumHelper
{
public static string Description(this Enum value)
{
var attributes = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes.Any())
return (attributes.First() as DescriptionAttribute).Description;
// If no description is found, the least we can do is replace underscores with spaces
// You can add your own custom default formatting logic here
TextInfo ti = CultureInfo.CurrentCulture.TextInfo;
return ti.ToTitleCase(ti.ToLower(value.ToString().Replace("_", " ")));
}
public static IEnumerable<ValueDescription> GetAllValuesAndDescriptions(Type t)
{
if (!t.IsEnum)
throw new ArgumentException($"{nameof(t)} must be an enum type");
return Enum.GetValues(t).Cast<Enum>().Select((e) => new ValueDescription() { Value = e, Description = e.Description() }).ToList();
}
}
다음으로을 만듭니다 ValueConverter
. 에서 상속 MarkupExtension
하면 XAML 에서 사용하기가 더 쉬워 지므로 리소스로 선언 할 필요가 없습니다.
[ValueConversion(typeof(Enum), typeof(IEnumerable<ValueDescription>))]
public class EnumToCollectionConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return EnumHelper.GetAllValuesAndDescriptions(value.GetType());
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
내 ViewModel
하나 와 콤보 상자 View
모두에 바인딩 할 수있는 속성이 하나만 필요합니다 .SelectedValue
ItemsSource
private DayOfWeek dayOfWeek;
public DayOfWeek SelectedDay
{
get { return dayOfWeek; }
set
{
if (dayOfWeek != value)
{
dayOfWeek = value;
OnPropertyChanged(nameof(SelectedDay));
}
}
}
그리고 마지막으로 바인딩 ComboBox
합니다 (을 사용하여보기 ValueConverter
에 ItemsSource
바인딩) ...
<ComboBox ItemsSource="{Binding Path=SelectedDay, Converter={x:EnumToCollectionConverter}, Mode=OneTime}"
SelectedValuePath="Value"
DisplayMemberPath="Description"
SelectedValue="{Binding Path=SelectedDay}" />
이 솔루션을 구현하려면 EnumHelper
클래스와 EnumToCollectionConverter
클래스 만 복사하면됩니다 . 그들은 열거 형 과 함께 작동 합니다 . 또한, 나는 여기에 포함되지 않았지만, ValueDescription
클래스는 2 개 공공 개체 속성이라는 하나 단순한 클래스 Value
라는 하나 Description
. 당신은 그 자신을 만들 수 있습니다 또는 당신이를 사용하도록 코드를 변경할 수 Tuple<object, object>
또는KeyValuePair<object, object>
MarkupExtension을 사용하여 다른 솔루션을 사용했습니다.
아이템 소스를 제공하는 클래스를 만들었습니다.
public class EnumToItemsSource : MarkupExtension { private readonly Type _type; public EnumToItemsSource(Type type) { _type = type; } public override object ProvideValue(IServiceProvider serviceProvider) { return Enum.GetValues(_type) .Cast<object>() .Select(e => new { Value = (int)e, DisplayName = e.ToString() }); } }
거의 다 ... 이제 XAML에서 사용하십시오.
<ComboBox DisplayMemberPath="DisplayName" ItemsSource="{persons:EnumToItemsSource {x:Type enums:States}}" SelectedValue="{Binding Path=WhereEverYouWant}" SelectedValuePath="Value" />
'enums : States'를 열거 형으로 변경하십시오.
ObjectDataProvider를 사용하십시오.
<ObjectDataProvider x:Key="enumValues"
MethodName="GetValues" ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:ExampleEnum"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
정적 리소스에 바인딩하십시오.
ItemsSource="{Binding Source={StaticResource enumValues}}"
이 기사를 기반으로
Nick의 대답이 실제로 도움이되었지만 추가 클래스 인 ValueDescription을 피하기 위해 약간 조정할 수 있음을 깨달았습니다. 프레임 워크에 이미 KeyValuePair 클래스가 있으므로 이것을 대신 사용할 수 있다는 것을 기억했습니다.
코드는 약간만 변경됩니다.
public static IEnumerable<KeyValuePair<string, string>> GetAllValuesAndDescriptions<TEnum>() where TEnum : struct, IConvertible, IComparable, IFormattable
{
if (!typeof(TEnum).IsEnum)
{
throw new ArgumentException("TEnum must be an Enumeration type");
}
return from e in Enum.GetValues(typeof(TEnum)).Cast<Enum>()
select new KeyValuePair<string, string>(e.ToString(), e.Description());
}
public IEnumerable<KeyValuePair<string, string>> PlayerClassList
{
get
{
return EnumHelper.GetAllValuesAndDescriptions<PlayerClass>();
}
}
그리고 마지막으로 XAML :
<ComboBox ItemSource="{Binding Path=PlayerClassList}"
DisplayMemberPath="Value"
SelectedValuePath="Key"
SelectedValue="{Binding Path=SelectedClass}" />
이것이 다른 사람들에게 도움이되기를 바랍니다.
열거 형에 값의 배열을 만들어야합니다. 열거 형은 System.Enum.GetValues () 를 호출하여 만들 수 있으며 , Type
원하는 열거 형의 항목을 전달합니다.
ItemsSource
속성 에이 속성 을 지정하면 모든 열거 형 값으로 채워 져야합니다. 당신은 아마 바인딩 할 SelectedItem
에 EffectStyle
(이 같은 열거의 속성이며, 현재의 값이 포함 된 가정).
위의 모든 게시물은 간단한 트릭을 놓쳤습니다. SelectedValue의 바인딩을 통해 XAML 마크 업이 제대로되도록 ItemsSource를 자동으로 채우는 방법을 찾을 수 있습니다.
<Controls:EnumComboBox SelectedValue="{Binding Fool}"/>
예를 들어 내 ViewModel에서 나는
public enum FoolEnum
{
AAA, BBB, CCC, DDD
};
FoolEnum _Fool;
public FoolEnum Fool
{
get { return _Fool; }
set { ValidateRaiseAndSetIfChanged(ref _Fool, value); }
}
ValidateRaiseAndSetIfChanged는 내 INPC 후크입니다. 당신과 다를 수 있습니다.
EnumComboBox의 구현은 다음과 같지만 먼저 열거 문자열과 값을 얻으려면 약간의 도우미가 필요합니다.
public static List<Tuple<object, string, int>> EnumToList(Type t)
{
return Enum
.GetValues(t)
.Cast<object>()
.Select(x=>Tuple.Create(x, x.ToString(), (int)x))
.ToList();
}
기본 클래스 (참고 : WhenAny 통해 속성 변경 사항을 연결하기 위해 ReactiveUI를 사용하고 있습니다)
using ReactiveUI;
using ReactiveUI.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Documents;
namespace My.Controls
{
public class EnumComboBox : System.Windows.Controls.ComboBox
{
static EnumComboBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(EnumComboBox), new FrameworkPropertyMetadata(typeof(EnumComboBox)));
}
protected override void OnInitialized( EventArgs e )
{
base.OnInitialized(e);
this.WhenAnyValue(p => p.SelectedValue)
.Where(p => p != null)
.Select(o => o.GetType())
.Where(t => t.IsEnum)
.DistinctUntilChanged()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(FillItems);
}
private void FillItems(Type enumType)
{
List<KeyValuePair<object, string>> values = new List<KeyValuePair<object,string>>();
foreach (var idx in EnumUtils.EnumToList(enumType))
{
values.Add(new KeyValuePair<object, string>(idx.Item1, idx.Item2));
}
this.ItemsSource = values.Select(o=>o.Key.ToString()).ToList();
UpdateLayout();
this.ItemsSource = values;
this.DisplayMemberPath = "Value";
this.SelectedValuePath = "Key";
}
}
}
Generic.XAML에서 스타일을 올바르게 설정해야합니다. 그렇지 않으면 상자가 아무 것도 렌더링되지 않아 머리카락이 빠집니다.
<Style TargetType="{x:Type local:EnumComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
</Style>
그게 다야. 이것은 분명히 i18n을 지원하도록 확장 될 수 있지만 게시물을 더 길게 만듭니다.
public class EnumItemsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!value.GetType().IsEnum)
return false;
var enumName = value.GetType();
var obj = Enum.Parse(enumName, value.ToString());
return System.Convert.ToInt32(obj);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Enum.ToObject(targetType, System.Convert.ToInt32(value));
}
}
열거 형 개체 모델 속성에 직접 바인딩하는 경우 이러한 종류의 열거 형 값 변환기를 사용하여 Rogers와 Greg의 대답을 확장해야합니다.
범용 앱은 약간 다르게 작동합니다. 모든 기능을 갖춘 XAML의 모든 기능을 갖추고 있지는 않습니다. 나를 위해 일한 것은 다음과 같습니다.
- 열거 형 값 목록을 열거 형으로 만들거나 (문자열이나 정수로 변환하지 않음) ComboBox ItemsSource를 바인딩했습니다.
- 그런 다음 ComboBox ItemSelected를 해당 유형이 열거 형인 공용 속성에 바인딩 할 수 있습니다
재미를 위해 이것에 도움이되는 작은 템플릿 클래스를 만들어 MSDN 샘플 페이지에 게시했습니다 . 여분의 비트를 사용하면 열거 형 이름을 선택적으로 재정의하고 열거 형 중 일부를 숨길 수 있습니다. 내 코드는 Nick의 (위)와 같이 끔찍한 것처럼 보였습니다.
이 질문에 대한 많은 훌륭한 답변이 있으며 나는 겸손히 내 것을 제출합니다. 내 것이 다소 단순하고 우아하다는 것을 알았습니다. 값 변환기 만 필요합니다.
열거 형이 주어지면 ...
public enum ImageFormat
{
[Description("Windows Bitmap")]
BMP,
[Description("Graphics Interchange Format")]
GIF,
[Description("Joint Photographic Experts Group Format")]
JPG,
[Description("Portable Network Graphics Format")]
PNG,
[Description("Tagged Image Format")]
TIFF,
[Description("Windows Media Photo Format")]
WDP
}
그리고 가치 변환기 ...
public class ImageFormatValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is ImageFormat format)
{
return GetString(format);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string s)
{
return Enum.Parse(typeof(ImageFormat), s.Substring(0, s.IndexOf(':')));
}
return null;
}
public string[] Strings => GetStrings();
public static string GetString(ImageFormat format)
{
return format.ToString() + ": " + GetDescription(format);
}
public static string GetDescription(ImageFormat format)
{
return format.GetType().GetMember(format.ToString())[0].GetCustomAttribute<DescriptionAttribute>().Description;
}
public static string[] GetStrings()
{
List<string> list = new List<string>();
foreach (ImageFormat format in Enum.GetValues(typeof(ImageFormat)))
{
list.Add(GetString(format));
}
return list.ToArray();
}
}
자원...
<local:ImageFormatValueConverter x:Key="ImageFormatValueConverter"/>
XAML 선언 ...
<ComboBox Grid.Row="9" ItemsSource="{Binding Source={StaticResource ImageFormatValueConverter}, Path=Strings}"
SelectedItem="{Binding Format, Converter={StaticResource ImageFormatValueConverter}}"/>
모델보기 ...
private ImageFormat _imageFormat = ImageFormat.JPG;
public ImageFormat Format
{
get => _imageFormat;
set
{
if (_imageFormat != value)
{
_imageFormat = value;
OnPropertyChanged();
}
}
}
결과 콤보 박스 ...
열거 형의 int 표현이 아닌 ViewModel의 실제 열거 형 속성에 바인딩하는 경우 까다로워집니다. 위의 모든 예제에서 예상되는 int 값이 아닌 문자열 표현에 바인딩해야한다는 것을 알았습니다.
간단한 텍스트 상자를 ViewModel에서 바인딩하려는 속성에 바인딩하여 이러한 경우인지 알 수 있습니다. 텍스트가 표시되면 문자열에 바인딩하십시오. 숫자가 표시되면 값에 바인딩하십시오. 참고 일반적으로 오류가되는 Display를 두 번 사용했지만 작동하는 유일한 방법입니다.
<ComboBox SelectedValue="{Binding ElementMap.EdiDataType, Mode=TwoWay}"
DisplayMemberPath="Display"
SelectedValuePath="Display"
ItemsSource="{Binding Source={core:EnumToItemsSource {x:Type edi:EdiDataType}}}" />
그렉
tom.maruska의 답변을 좋아 했지만 런타임에 템플릿에서 발생할 수있는 열거 형 유형을 지원해야했습니다. 이를 위해 태그 확장에 유형을 지정하기 위해 바인딩을 사용해야했습니다. 나는 nicolay.anykienko 의이 답변 에서 내가 생각할 수있는 모든 경우에 작동 할 수있는 매우 유연한 태그 확장을 생각 해낼 수있었습니다. 다음과 같이 소비됩니다.
<ComboBox SelectedValue="{Binding MyEnumProperty}"
SelectedValuePath="Value"
ItemsSource="{local:EnumToObjectArray SourceEnum={Binding MyEnumProperty}}"
DisplayMemberPath="DisplayName" />
위에서 언급 한 매쉬업 마크 업 확장의 소스 :
class EnumToObjectArray : MarkupExtension
{
public BindingBase SourceEnum { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
IProvideValueTarget target = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;
DependencyObject targetObject;
DependencyProperty targetProperty;
if (target != null && target.TargetObject is DependencyObject && target.TargetProperty is DependencyProperty)
{
targetObject = (DependencyObject)target.TargetObject;
targetProperty = (DependencyProperty)target.TargetProperty;
}
else
{
return this;
}
BindingOperations.SetBinding(targetObject, EnumToObjectArray.SourceEnumBindingSinkProperty, SourceEnum);
var type = targetObject.GetValue(SourceEnumBindingSinkProperty).GetType();
if (type.BaseType != typeof(System.Enum)) return this;
return Enum.GetValues(type)
.Cast<Enum>()
.Select(e => new { Value=e, Name = e.ToString(), DisplayName = Description(e) });
}
private static DependencyProperty SourceEnumBindingSinkProperty = DependencyProperty.RegisterAttached("SourceEnumBindingSink", typeof(Enum)
, typeof(EnumToObjectArray), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));
/// <summary>
/// Extension method which returns the string specified in the Description attribute, if any. Oherwise, name is returned.
/// </summary>
/// <param name="value">The enum value.</param>
/// <returns></returns>
public static string Description(Enum value)
{
var attrs = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs.Any())
return (attrs.First() as DescriptionAttribute).Description;
//Fallback
return value.ToString().Replace("_", " ");
}
}
간단하고 명확한 설명 : http://brianlagunas.com/a-better-way-to-data-bind-enums-in-wpf/
xmlns:local="clr-namespace:BindingEnums"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
...
<Window.Resources>
<ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="local:Status"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
...
<Grid>
<ComboBox HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="150"
ItemsSource="{Binding Source={StaticResource dataFromEnum}}"/>
</Grid>
을 사용 ReactiveUI
하여 다음과 같은 대체 솔루션을 만들었습니다. 우아한 올인원 솔루션은 아니지만 최소한 읽을 수 있다고 생각합니다.
필자의 경우 enum
컨트롤 목록을 바인딩하는 것은 드문 경우이므로 코드베이스에서 솔루션을 확장 할 필요가 없습니다. 그러나 코드를 변경하여보다 일반적인 만들 수 있습니다 EffectStyleLookup.Item
에 Object
. 내 코드로 테스트했지만 다른 수정이 필요하지 않습니다. 이는 하나의 도우미 클래스가 모든 enum
목록에 적용될 수 있음을 의미합니다 . 그것은 가독성을 떨어 뜨릴 것이지만 ReactiveList<EnumLookupHelper>
큰 고리는 없습니다.
다음 헬퍼 클래스 사용 :
public class EffectStyleLookup
{
public EffectStyle Item { get; set; }
public string Display { get; set; }
}
ViewModel에서 열거 목록을 변환하여 속성으로 노출하십시오.
public ViewModel : ReactiveObject
{
private ReactiveList<EffectStyleLookup> _effectStyles;
public ReactiveList<EffectStyleLookup> EffectStyles
{
get { return _effectStyles; }
set { this.RaiseAndSetIfChanged(ref _effectStyles, value); }
}
// See below for more on this
private EffectStyle _selectedEffectStyle;
public EffectStyle SelectedEffectStyle
{
get { return _selectedEffectStyle; }
set { this.RaiseAndSetIfChanged(ref _selectedEffectStyle, value); }
}
public ViewModel()
{
// Convert a list of enums into a ReactiveList
var list = (IList<EffectStyle>)Enum.GetValues(typeof(EffectStyle))
.Select( x => new EffectStyleLookup() {
Item = x,
Display = x.ToString()
});
EffectStyles = new ReactiveList<EffectStyle>( list );
}
}
에서 ComboBox
의 활용 SelectedValuePath
원본에 바인딩, 속성을 enum
값 :
<ComboBox Name="EffectStyle" DisplayMemberPath="Display" SelectedValuePath="Item" />
View에서는 ViewModel에서 원본 enum
을 에 바인딩 할 수 SelectedEffectStyle
있지만 ToString()
값은 ComboBox
:
this.WhenActivated( d =>
{
d( this.OneWayBind(ViewModel, vm => vm.EffectStyles, v => v.EffectStyle.ItemsSource) );
d( this.Bind(ViewModel, vm => vm.SelectedEffectStyle, v => v.EffectStyle.SelectedValue) );
});
슬프게도 VB에서는 내 의견을 추가하고 있지만이 개념을 하트 비트로 C #으로 쉽게 복제 할 수 있습니다. 왜냐하면 이것을 참조하고 너무 복잡하여 답변을 좋아하지 않았기 때문입니다. 그렇게 어려울 필요는 없습니다.
그래서 더 쉬운 방법을 생각해 냈습니다. 열거자를 사전에 바인딩합니다. 해당 사전을 콤보 상자에 바인딩하십시오.
내 콤보 박스 :
<ComboBox x:Name="cmbRole" VerticalAlignment="Stretch" IsEditable="False" Padding="2"
Margin="0" FontSize="11" HorizontalAlignment="Stretch" TabIndex="104"
SelectedValuePath="Key" DisplayMemberPath="Value" />
내 코드 숨김. 바라건대, 이것은 다른 누군가를 도와줍니다.
Dim tDict As New Dictionary(Of Integer, String)
Dim types = [Enum].GetValues(GetType(Helper.Enumerators.AllowedType))
For Each x As Helper.Enumerators.AllowedType In types
Dim z = x.ToString()
Dim y = CInt(x)
tDict.Add(y, z)
Next
cmbRole.ClearValue(ItemsControl.ItemsSourceProperty)
cmbRole.ItemsSource = tDict
Nick의 솔루션은 더 간단 해 질 수 있습니다. 멋진 것은 없습니다. 단 하나의 변환기 만 있으면됩니다.
[ValueConversion(typeof(Enum), typeof(IEnumerable<Enum>))]
public class EnumToCollectionConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var r = Enum.GetValues(value.GetType());
return r;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
그런 다음 콤보 상자를 표시하려는 위치에 다음을 사용하십시오.
<ComboBox ItemsSource="{Binding PagePosition, Converter={converter:EnumToCollectionConverter}, Mode=OneTime}" SelectedItem="{Binding PagePosition}" />
참고 URL : https://stackoverflow.com/questions/6145888/how-to-bind-an-enum-to-a-combobox-control-in-wpf
'Programing' 카테고리의 다른 글
스크립트를 사용하여 SSH 비밀번호 자동 입력 (0) | 2020.05.26 |
---|---|
Swift로 간단한 컬렉션 뷰를 만드는 방법 (0) | 2020.05.26 |
Redux 애플리케이션에서 코드 분할을 위해 리듀서를 동적으로로드하는 방법은 무엇입니까? (0) | 2020.05.25 |
Dapper로 삽입 및 업데이트 수행 (0) | 2020.05.25 |
스트리밍 버퍼를 utf8-string으로 변환 (0) | 2020.05.25 |