Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267488
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:54:24+00:00 2026-05-21T06:54:24+00:00

I tried to bind the following Enum to a ComboBox Public Enum PossibleActions ActionRead

  • 0

I tried to bind the following Enum to a ComboBox

Public Enum PossibleActions
  ActionRead
  ActionWrite
  ActionVerify
End Enum

I can’t change the Enum itself, but I do not want to display these strings. My intention is just to cut the prefix ‘Action’ and display ‘Read’, ‘Write’ and ‘Verify’ in the ComboBox. Therefore I wrote a ValueConverter

Public Class PossibleActionsConverter
  Implements IValueConverter

      Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim actions() As PossibleActions
        Dim strings() As String

        actions = CType(value, PossibleActions())
        ReDim strings(actions.GetUpperBound(0))
        For i = 0 To actions.GetUpperBound(0)
          strings(i) = actions(i).ToString.Substring(6)
        Next
        Return strings
      End Function

      Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Dim s As String

        s = CStr(value)

        Return [Enum].Parse(GetType(PossibleActions), "Action" & s)
      End Function
    End Class

My XAML looks like

xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:StepEditor"

[…]

<Window.Resources>
    <ObjectDataProvider x:Key="possibleActionsEnum" MethodName="GetValues"
                        ObjectType="{x:Type sys:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:TypeExtension Type="local:PossibleActions"></x:TypeExtension>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
    <local:PossibleActionsConverter x:Key="possibleActionsConverter"></local:PossibleActionsConverter>
</Window.Resources>

[…]
Either:

<ComboBox ItemsSource="{Binding Source={StaticResource possibleActionsEnum}, Converter={StaticResource possibleActionsConverter}}"
          SelectedItem="{Binding SelectedAction}"></ComboBox>

Or:

<ComboBox ItemsSource="{Binding Source={StaticResource possibleActionsEnum}, Converter={StaticResource possibleActionsConverter}}"
          SelectedItem="{Binding SelectedAction, Converter={StaticResource possibleActionsConverter}}"></ComboBox>

My problem is the binding of the selected item. It fails, but I can’t figure out why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:54:24+00:00Added an answer on May 21, 2026 at 6:54 am

    The binding of SelectedItem is wrong, because you convert your Enum into Strings, but SelectedItems is a single string. If you want to stick on this architecture, write a converter that converts a single string back to your enum.
    The Convert and ConvertBack-methods of your existing converter are close to the solution. They can look like:

      Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim action As PossibleActions
    
        action = CType(value, PossibleActions)
        Return action.ToString.Substring(6)
      End Function
    
      Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Dim s As String
    
        s = CStr(value)
        Return [Enum].Parse(GetType(PossibleActions), "Action" & s)
      End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
I tried scouring the web for help on this issue, but there are so
I tried to package a Twisted program with py2exe, but once I run the
I tried but I guess Message Box only works with win forms. What is
I tried x = y ** e, but that didn't work.
I tried the following code in LINQPad and got the results given below: List<string>
Consider the following code. public interface IFoo { } public class Bar { public
I tried the following: int sockfd = socket(...); listen(sockfd, 10); accept(sockfd, ...); None of
I am trying to bind an observable collection to a user control but it
I want to pass few parameters to click() event in jQuery, I tried following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.