1

I will use XAMLReader to load wpf screens.

I have some ControlTemplates on Buttons.xaml file and i am keeping it in a common class library (ClassLibrary1). Buttons.xaml is like that:

<ResourceDictionary 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

   <ControlTemplate x:Key="LeftButton" TargetType="{x:Type Button}">
      // Some codes
   </ControlTemplate>

   <ControlTemplate x:Key="RightButton" TargetType="{x:Type Button}">
      // Some codes  
   </ControlTemplate>
</ResourceDictionary>

On main WPF project, this dll is added as reference.

My xaml is like that:

<UserControl 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Width="800" Height="600">

  <Grid>
    <Grid.Resources>
      <ResourceDictionary x:Key="testSource">
        <ResourceDictionary.MergedDictionaries>
           <ResourceDictionary x:Name="s" Source="pack://application:,,,/ClassLibrary1;component/Buttons.xaml" />
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Grid.Resources>

    <Button Template="{DynamicResource RightButton}" Content="TestBtn" HorizontalAlignment="Left"  Width="100" Height="100" Margin="474,529,0,0"  ></Button>
  </Grid>
</UserControl>

When i use Template="{DynamicResource RightButton}" template is not loaded correctly (actually there is no sign of button on screen).

Also there is no error about loading the resourcedictionary.

I couldn't find, what should i use in order to load template on this button. Can anyone help me?

makcura
  • 61
  • 2
  • 9

0 Answers0