Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set custom property as XAML value?
    text
    copied!<p>I have this library with custom <em>Color</em> properties. I wanna be able to use these properties in XAML like this:</p> <pre><code> &lt;Style TargetType="{x:Type eg:MyWindow}"&gt; &lt;Setter Property="Background"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush Color="CustomClass.CustomColorProperty"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>The namespace that contains <em>CustomClass</em> is already referenced. How should I go about this? Thanks.</p> <p>EDIT:</p> <p>I just noticed that <em>CustomClass</em> is static, so I can't create an instance of it in XAML. Also, when I type <em>eg:</em>, <em>CustomClass</em> doesn't show up in intellisense. I can't get any of your solutions to work, even though they should, if I had an instance class. Is there a workaround for this situation?</p> <p>EDIT 2:</p> <p>This is the actual class and namespace:</p> <pre><code>namespace Assergs.Windows { public static class OfficeColors { public class Background { public static Color OfficeColor1 = (Color)ColorConverter.ConvertFromString("#e4e6e8"); public static Color OfficeColor2 = (Color)ColorConverter.ConvertFromString("#dce0ed"); public static Color OfficeColor3 = (Color)ColorConverter.ConvertFromString("#a8c3e0"); } } } </code></pre> <p>And this is the XAML namespace:</p> <pre><code>xmlns:aw="clr-namespace:Assergs.Windows;assembly=Assergs.Windows" </code></pre> <p>And if I use this line, as suggested by Zenuka:</p> <pre><code>&lt;SolidColorBrush Color="{x:Static aw:OfficeColors.Background.OfficeColor1}"/&gt; </code></pre> <p>It throws this error at compile time:</p> <pre><code>Cannot find the type 'OfficeColors.Background'. Note that type names are case sensitive. </code></pre>
 

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