Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading WPF Style from Resource File
    primarykey
    data
    text
    <p>I am trying to load WPF Style from other file actually from WPF Custom Control Library but i am failing to load here is my solution.</p> <p>The solution contains two projects </p> <ol> <li><p>WpfTestControls of Type WPF Custom Control Library</p></li> <li><p>WpfTestApp of type WPF Application Library which has reference to WpfTestControls</p></li> </ol> <p><strong>MainWindow.xaml from WPF Application Library</strong></p> <pre><code>&lt;Window.Resources&gt; &lt;Style x:Key="TempStyle" TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="BorderBrush" Value="Green"/&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;TextBox Height="50px" Width="100px" Style="{DynamicResource TempStyle}"/&gt; &lt;/Grid&gt; </code></pre> <p><strong>Generic.xaml from WPF Custom Control Library</strong></p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;ResourceDictionary Source="/WpfTestControls;component/TextBoxStyle.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; </code></pre> <p></p> <p><strong>TextBoxStyle.xaml from WPF Custom Control Library</strong></p> <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Style x:Key="TempStyle" TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="BorderBrush" Value="Green"/&gt; &lt;/Style&gt; </code></pre> <p></p> <p>My AssemblyInfo.cs file contains the following</p> <pre><code>[assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, // or application resource dictionaries) ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries))] </code></pre> <p>But still i am failing to load the Style. If i am using the not using the Generic.xaml everything work fine for example the following code works as expected </p> <pre><code>&lt;Window x:Class="WpfTestApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;Style x:Key="TempStyle" TargetType="{x:Type TextBox}"&gt; &lt;Setter Property="BorderBrush" Value="Green"/&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;TextBox Height="50px" Width="100px" Style="{StaticResource TempStyle}"/&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>What am i doing wrong ? Thanks in advance</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.
 

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