Note that there are some explanatory texts on larger screens.

plurals
  1. POError when binding using markup extensions: Unknown property encountered while parsing a Markup Extension
    primarykey
    data
    text
    <p>In principle, I developed a neat way to bind RadioButtons to almost anything:</p> <pre><code>/// &lt;summary&gt;Converts an value to 'true' if it matches the 'To' property.&lt;/summary&gt; /// &lt;example&gt; /// &lt;RadioButton IsChecked="{Binding VersionString, Converter={local:TrueWhenEqual To='1.0'}}"/&gt; /// &lt;/example&gt; public class TrueWhenEqual : MarkupExtension, IValueConverter { public override object ProvideValue(IServiceProvider serviceProvider) { return this; } public object To { get; set; } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return object.Equals(value, To); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if ((bool)value) return To; throw new NotSupportedException(); } } </code></pre> <p>For example, you can use this to bind RadioButtons to a string property as follows (it is a well-known bug that you must use a unique GroupName for each RadioButton):</p> <pre><code>&lt;RadioButton GroupName="G1" Content="Cat" IsChecked="{Binding Animal, Converter={local:TrueWhenEqual To='CAT'}}"/&gt; &lt;RadioButton GroupName="G2" Content="Dog" IsChecked="{Binding Animal, Converter={local:TrueWhenEqual To='DOG'}}"/&gt; &lt;RadioButton GroupName="G3" Content="Horse" IsChecked="{Binding Animal, Converter={local:TrueWhenEqual To='HORSE'}}"/&gt; </code></pre> <p>Now, I would like to use <code>public static readonly</code> objects called <code>Filter1</code> and <code>Filter2</code> as the values of my RadioButtons. So I tried:</p> <pre><code>&lt;RadioButton GroupName="F1" Content="Filter Number One" IsChecked="{Binding Filter, Converter={local:TrueWhenEqual To='{x:Static local:ViewModelClass.Filter1}'}}"/&gt; &lt;RadioButton GroupName="F2" Content="Filter Number Two" IsChecked="{Binding Filter, Converter={local:TrueWhenEqual To='{x:Static local:ViewModelClass.Filter2}'}}"/&gt; </code></pre> <p>But this gives me an error:</p> <blockquote> <p>Unknown property 'To' for type 'MS.Internal.Markup.MarkupExtensionParser+UnknownMarkupExtension' encountered while parsing a Markup Extension.</p> </blockquote> <p>The error still occurs if I remove the quotes. What am I doing wrong?</p>
    singulars
    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.
 

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