Note that there are some explanatory texts on larger screens.

plurals
  1. POStyles from resources aren't used when UserControl is instantiated in other class
    text
    copied!<p>I create custom WPF Expander inherited from common Expander. I have a file with styles at path <code>MyAssembly/Theme/generic.xaml</code>. I can see that <strong>styles are applied in designer but are not in running program</strong>.</p> <p>MyExpander.xaml:</p> <pre><code>&lt;Expander x:Class="Path.To.MyExpander" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&gt; &lt;Expander.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="pack://application:,,,/MyAssembly;component/Theme/generic.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Expander.Resources&gt; ... </code></pre> <p>generic.xaml:</p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&gt; ... </code></pre> <p>code where I instanciate the expanders:</p> <pre><code>class Viewer { private void GenerateExpanders() { this.Expanders.Children.Clear(); foreach (...) { MyExpander ex = new MyExpander(); ex.HeaderText.Text = "Sample"; ex.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; ex.IsExpanded = true; this.Expanders.Children.Add(ex); } } } </code></pre> <p>All three files are in one assembly but class Viewer is instantiated in another assembly. Is there something am I doing wrong?</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