Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to skin this cat would be by converting the string (in the listbox) into a bool to pass into the IsEnabledProperty...</p> <p>First, create a class that implements the IValueConverter interface, like:</p> <pre><code>public class StringToBoolConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) return false; string keyword = value.ToString(); if (keyword.Equals(parameter.ToString(), StringComparison.CurrentCultureIgnoreCase)) return true; return false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion } </code></pre> <p>Notice how you don't need to implement the ConvertBack method? That's because you only need to turn strings into bools, not vice-versa...</p> <p>So you can declare an instance of your converter in the xaml, like</p> <pre><code>&lt;Window ... xmlns:local="clr-namespace:WpfApplication1"&gt; &lt;Window.Resources&gt; &lt;local:StringToBoolConverter x:Key="stringToBoolConverter" /&gt; &lt;/Window.Resources&gt; </code></pre> <p>And finally, you can bind the TextBox to the ListBox's SelectedValue, like:</p> <pre><code>&lt;TextBox Grid.Row="0" Width="90" Height="30" IsEnabled="{Binding ElementName=lbSource, Path=SelectedValue, Converter={StaticResource stringToBoolConverter}, ConverterParameter=ValueForEnabled}"&gt; &lt;/TextBox&gt; </code></pre> <p>Note: This will only work if the ListBox contains strings, and you can be sure that the SelectedValue property is a string...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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