添加的ResourceDictionary到类库 [英] Add ResourceDictionary to class library

查看:227
本文介绍了添加的ResourceDictionary到类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了包含WPF Windows和帮助我自定义某些WPF控件从我的C#类继承了一些用户控件的类库。



现在我想添加的ResourceDictionary,帮我分担我的WPF类之间的风格。是否有可能



THX






编辑:?$位于MY.WpfPresentation.Main项目(名为Styles.xaml)b $ b资源字典文件:

 < ResourceDictionary中的xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
的xmlns: DXG =htt​​p://schemas.devexpress.com/winfx/2008/xaml/grid
的xmlns:dxgt =htt​​p://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys
的xmlns:MYNetMisc =CLR的命名空间:MY.Net.Misc;装配= MY.Net
>
<风格X:键=customRowStyle支持算法FMP ={StaticResource的{dxgt:GridRowThemeKey的ResourceKey = RowStyle}}的TargetType ={X:类型DXG:GridRowContent}>
< setter属性=前景VALUE ={绑定路径= DataContext.balance,转换器= {MYNetMisc:BalanceToColor OnlyNegative = FALSE}}/>
< /样式和GT;
< / ResourceDictionary的>



使用它:

 < MYNetPresentation:frmDockBase.Resources> 
< ResourceDictionary的X:键=风格>
< ResourceDictionary.MergedDictionaries>
< ResourceDictionary中源=包://应用:,,, / MY.WpfPresentation.Main;组件/ Styles.xaml/>
< /ResourceDictionary.MergedDictionaries>
< / ResourceDictionary的>
<的DataTemplate X:键=TabTemplate>
< dxlc:LayoutControl填充=0滚动条=无背景=透明>
<图像源=/图像/图标/表32x32.pngWIDTH =12HEIGHT =12/>
< TextBlock的文本={}绑定的Horizo​​ntalAlignment =左VerticalAlignment =中心/>
< / dxlc:LayoutControl>
< / DataTemplate中>

< / MYNetPresentation:frmDockBase.Resources>


解决方案

创建这样一个资源字典



 < ResourceDictionary中的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns: X =htt​​p://schemas.microsoft.com/winfx/2006/xaml>

<&ResourceDictionary中GT;
< ResourceDictionary.MergedDictionaries>
<! - 通用基本主题 - >
< ResourceDictionary中源=包://应用:,,, / Another.AssemblyName;组件/ YourResDictionaryFolder / OtherStyles.xaml/>
< ResourceDictionary中源=包://应用:,,, / Another.AssemblyName;组件/ YourResDictionaryFolder / AnotherStyles.xaml/>
< /ResourceDictionary.MergedDictionaries>
< / ResourceDictionary的>

<! - 在这里存储您的样式 - >

< / ResourceDictionary的>



,你可以把它放在你想要

 <窗​​口x:类=DragMoveFor​​ms.Window2
的xmlns =htt​​p://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =htt​​p://schemas.microsoft.com/winfx/2006/xaml
标题=窗口2
HEIGHT =300
WIDTH =300 >

< Window.Resources>
< ResourceDictionary中源=包://应用:,,, / Your.Base.AssemblyName;组件/ YourResDictionaryFolder / Dictionary1.xaml/>
< /Window.Resources>

<网格和GT;

< /网格和GT;
< /窗GT;


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>

解决方案

create a resource dictionary like this one

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

  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <!-- Common base theme -->
      <ResourceDictionary Source="pack://application:,,,/Another.AssemblyName;component/YourResDictionaryFolder/OtherStyles.xaml" />
      <ResourceDictionary Source="pack://application:,,,/Another.AssemblyName;component/YourResDictionaryFolder/AnotherStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>

  <!-- store here your styles -->

</ResourceDictionary>

and you can put it where you want

<Window x:Class="DragMoveForms.Window2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window2"
        Height="300"
        Width="300">

  <Window.Resources>
    <ResourceDictionary Source="pack://application:,,,/Your.Base.AssemblyName;component/YourResDictionaryFolder/Dictionary1.xaml" />
  </Window.Resources>

  <Grid>

  </Grid>
</Window>

这篇关于添加的ResourceDictionary到类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆