Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Data binding: How to data bind an enum to combo box using XAML?
    text
    copied!<p>I have a class: </p> <pre><code>public class AccountDetail { public DetailScope Scope { get { return scope; } set { scope = value; } } public string Value { get { return this.value; } set { this.value = value; } } private DetailScope scope; private string value; public AccountDetail(DetailScope scope, string value) { this.scope = scope; this.value = value; } } </code></pre> <p>and an enum: </p> <pre><code>public enum DetailScope { Private, Business, OtherDetail } </code></pre> <p>Lastly, I have a .xaml file:</p> <pre><code>&lt;Window x:Class="Gui.Wpf.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Test" SizeToContent="WidthAndHeight"&gt; &lt;Grid&gt; &lt;ComboBox Name="ScopeComboBox" Width="120" Height="23" Margin="12" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>I would like to do two things: </p> <ol> <li>I wish to data bind <code>DetailsScope</code> enum values to the combo box values. I don't wish to bind enum values directly because the last enum value would be <code>OtherDetail</code> instead of <code>Other detail</code> (added a space character and small letter 'd'). </li> <li>I wish to data bind the selected value in the combo box to the one specified in the instance of the <code>AccountDetail</code> object. </li> </ol> <p>Could you help me out? Thanks. </p> <p>Update: I found this post <a href="http://blogs.msdn.com/b/wpfsdk/archive/2007/02/22/displaying-enum-values-using-data-binding.aspx" rel="noreferrer">http://blogs.msdn.com/b/wpfsdk/archive/2007/02/22/displaying-enum-values-using-data-binding.aspx</a>. I need something similar. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload