[WPF] Enum Tooltip Binding

해결했습니다~
알려주신 스타일에 Tooltip에 Converter를 추가했습니다.
도와주셔서 감사합니다.

<dxe:ComboBoxEdit.ItemContainerStyle>
    <Style TargetType="{x:Type dxe:ComboBoxEditItem}">
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="{Binding}" 
                               ToolTip="{Binding Converter={StaticResource EnumDisplayConverter}}"/>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</dxe:ComboBoxEdit.ItemContainerStyle>
    public class EnumDisplayConverter :  IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ERegistState enumValue = (ERegistState)Enum.Parse(typeof(ERegistState), value.ToString());
            
            return AttributeHelper.GetAttribute<DisplayAttribute>(enumValue).Description;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

AttributeHelper.GetAttribute() 메서드는 구글링해서 찾아낸 해당 Enum에 대한 DisplayAttribute를 찾아내는 메서드입니다.

3개의 좋아요