Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Why you get that error</strong></p> <p>Do you have something like this in the content of a Resources property?</p> <pre><code>&lt;local:BoolToCursorConverter x:Key="CursorConverter" /&gt; </code></pre> <p>If not then that's what is wrong but I'm guessing you already do.</p> <p>In that case you I suspect you have placed it in the <code>Resources</code> property of the <code>Grid</code> it applies to. That would be why it can not be found. <code>StaticResource</code> are resolved immediately as the Xaml is parsed. Hence any key used must already be loaded into a resource dictionary prior to use. The Xaml parser knows nothing of the contents of the Grid's <code>Resources</code> property because it hasn't processed it yet. Hence:-</p> <pre><code>&lt;UserControl&gt; &lt;Grid Cursor="{Binding IsLoading, Converter={StaticResource CursorConverter}}"&gt; &lt;Grid.Resources&gt; &lt;local:BoolToCursorConverter x:Key="CursorConverter" /&gt; &lt;/Grid.Resources&gt; &lt;!-- Contents here --&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>will fail. Where as:-</p> <pre><code>&lt;UserControl&gt; &lt;UserControl.Resources&gt; &lt;local:BoolToCursorConverter x:Key="CursorConverter" /&gt; &lt;/UserControl.Resources &gt; &lt;Grid Cursor="{Binding IsLoading, Converter={StaticResource CursorConverter}}"&gt; &lt;!-- Contents here --&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>would at least not fail in finding the converter.</p> <p><strong>What you actually need to do</strong></p> <p>I've presented the above to answer your question but I can see it doesn't really help you. You can't bind to the Cursor property like this. (It doesn't expose a public identifier field, Xaml uses the <em>NameOfThing</em> + "Property" convention to find a field that is the <code>DependencyProperty</code> for the property being bound).</p> <p>The solution is to create an Attached property:-</p> <pre><code>public class BoolCursorBinder { public static bool GetBindTarget(DependencyObject obj) { return (bool)obj.GetValue(BindTargetProperty); } public static void SetBindTarget(DependencyObject obj, bool value) { obj.SetValue(BindTargetProperty, value); } public static readonly DependencyProperty BindTargetProperty = DependencyProperty.RegisterAttached("BindTarget", typeof(bool), typeof(BoolCursorBinder), new PropertyMetadata(false, OnBindTargetChanged)); private static void OnBindTargetChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { FrameworkElement element = sender as FrameworkElement; if (element != null) { element.Cursor = (bool)e.NewValue ? Cursors.Wait : Cursors.Arrow; } } } </code></pre> <p>Now you can actually do the binding like this:-</p> <pre><code> &lt;Grid local:BoolCursorBinder.BindTarget="{Binding IsLoading}"&gt; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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