I created a class library which is contained of WPF Windows and some user controls inherited from my c# classes that helps me to customize certain wpf controls.
Now I want to add ResourceDictionary, to help me share styles between my wpf classes. Is it possible?
Thx.
EDIT: resource dictionary file located in MY.WpfPresentation.Main project (named Styles.xaml):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
xmlns:MYNetMisc="clr-namespace:MY.Net.Misc;assembly=MY.Net"
>
<Style x:Key="customRowStyle" BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}" TargetType="{x:Type dxg:GridRowContent}">
<Setter Property="Foreground" Value="{Binding Path=DataContext.balance, Converter={MYNetMisc:BalanceToColor OnlyNegative=false}}" />
</Style>
</ResourceDictionary>
using it:
<MYNetPresentation:frmDockBase.Resources>
<ResourceDictionary x:Key="style">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MY.WpfPresentation.Main;component/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<DataTemplate x:Key="TabTemplate">
<dxlc:LayoutControl Padding="0" ScrollBars="None" Background="Transparent">
<Image Source="/Images/Icons/table-32x32.png" Width="12" Height="12" />
<TextBlock Text="{Binding}" HorizontalAlignment="Left" VerticalAlignment="Center" />
</dxlc:LayoutControl>
</DataTemplate>
</MYNetPresentation:frmDockBase.Resources>
Since i can't yet comment but i've used this answer twice now:
To add to nmariot's answer:
Tip 1
to reach the .csproj file from visual studio
right click project -> click 'unload project'
right click project [in unloaded state]-> click 'edit 'filename.csproj''
Tip 2
to avoid error warnings once resource dictionary has been added:
add reference to System.Xaml
create a resource dictionary like this one
and you can put it where you want
Yes. You can add a ResourceDictionary directly to your project.
When you want to use it, you can merge it into the XAML as needed by using MergedDictionaries to "merge" that standalone
ResourceDictionary
into the resources of the type (ie: the Window or UserControl).To transform a classical library project to a WPF library project (in order to add
UserControls
,Windows
,ResourcesDictionaries
, etc.) you can add the following XML in the .csproj file in the first PropertyGroup Node :Full example :
In my opinion, the question is about adding a WPF Resource dictionary file to a Class Library project. The answer is that you can't do it for classic Class Library, but for WPF Application project, WPF Custom Control Library project or a WPF User Control Library. For these project types you can add a new Resource Dictionary (WPF), option which is available through adding new item to the project.
In my opinion the actual question title and question itself does not correspond to the accepted answer.
@punker76's answer is great and helped me a lot, but it's worth adding that if you create an empty file and add a resource tag into it you should also go to file properties, set BuildAction to Resource, Copy To... to Do not copy and clear CustomTool property if it's set.