C# 在wpf中将.cs文件的颜色指定给solidcolorbrush
我正试图为自己的控制定义一些颜色。我生成了一个资源字典,其中我想包括3个实心笔刷。我想将一些在.cs文件中定义为C# 在wpf中将.cs文件的颜色指定给solidcolorbrush,c#,wpf,xaml,C#,Wpf,Xaml,我正试图为自己的控制定义一些颜色。我生成了一个资源字典,其中我想包括3个实心笔刷。我想将一些在.cs文件中定义为System.Windows.Media.Color的颜色定义为它的颜色。我不知道我做错了什么,但我试过几种方法 我想我正在尝试将一种颜色的一个实例“投射”为字符串。。。所以代码爆炸了。有人知道哪种语法是正确的吗?这是我的代码(问题位于第15行(ResourcesDictionary)): 所有属性都作为内部属性包含在内部静态类中Color=“{StaticResource palet
System.Windows.Media.Color
的颜色定义为它的颜色。我不知道我做错了什么,但我试过几种方法
我想我正在尝试将一种颜色的一个实例“投射”为字符串。。。所以代码爆炸了。有人知道哪种语法是正确的吗?这是我的代码(问题位于第15行(ResourcesDictionary)):
所有属性都作为内部属性包含在内部静态类中
Color=“{StaticResource paleta:PaletLabel.Deshabilitado}
(或DynamicSource)不起作用,因为paleta:PaletLabel.Deshabilitado
不是资源键。请尝试Color=“{x:static paleta:PaletLabel.Deshabilitado}”
。另一方面,我不认为绑定
可以在资源字典
中工作,我也尝试过。。。另一方面,我不确定它在哪里可以工作。。。可以将所有静态颜色转换为画笔,并将其称为代码,称为setter??您要么做了完全错误的事情,要么只显示与问题相关的部分代码。您正在访问资源键,如paleta:PaletLabel.Link
。首先,资源键中没有名称空间前缀。至少我没有遇到过这个。其次,显示资源
,在其中使用这些键创建资源。
<TextBlock x:Class="PhanUtils.Interfaz.Wpf.Controles.Basicos.PhanLabel"
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"
xmlns:local="clr-namespace:PhanUtils.Interfaz.Wpf.Controles.Basicos"
xmlns:paleta="clr-namespace:PhanUtils.Interfaz.Wpf.Paletas.Controles"
mc:Ignorable="d"
d:DesignHeight="25" d:DesignWidth="50" Background="Transparent"
MouseDown="TextBlock_MouseDown" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave">
<TextBlock.Resources>
<!-- Incluyo todos los colores requeirdos -->
<ResourceDictionary x:Name="ColoresPhanGhost">
<SolidColorBrush x:Key="ColorFuente" Color="{DynamicResource paleta:PaletaLabel.Texto_OLD}"/>
<SolidColorBrush x:Key="ColorDisable" Color="{StaticResource paleta:PaletaLabel.Deshabilitado}"/>
<SolidColorBrush x:Key="ColorLink" Color="{StaticResource paleta:PaletaLabel.Link}"/>
</ResourceDictionary>
</TextBlock.Resources>
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<!-- Caso deshabilitado -->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Aqua"/>
</Trigger>
<!-- Caso habilitado en que un link no se ha clickado -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True"/>
<Condition Property="local:PhanLabel.EsLink" Value="True"/>
<Condition Property="local:PhanLabel.EstaClickado" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource ColorFuente}"/>
</MultiTrigger>
<!-- Caso habilitado en que un link ha sido clickado -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True"/>
<Condition Property="local:PhanLabel.EsLink" Value="True"/>
<Condition Property="local:PhanLabel.EstaClickado" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="GreenYellow"/>
</MultiTrigger>
<!-- Cualquier otro caso -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True"/>
<Condition Property="local:PhanLabel.EsLink" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="Red"/>
</MultiTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
internal static Color Deshabilitado
{
get
{
// En función de la paleta, defino el color a devolver.
switch (PaletaInterfaz.Paleta)
{
case PaletaInterfaz.Tipo_Paleta.Oscura: return Oscura_Label_Texto_Deshabilitado;
case PaletaInterfaz.Tipo_Paleta.Original:
default: return Original_Texto_Deshabilitado;
}
}
}
internal static Color Link
{
get
{
// En función de la paleta, defino el color a devolver.
switch (PaletaInterfaz.Paleta)
{
case PaletaInterfaz.Tipo_Paleta.Oscura: return Oscura_Texto_Link;
case PaletaInterfaz.Tipo_Paleta.Original:
default: return Original_Texto_Link;
}
}
}
internal static Color Texto_OLD
{
get
{
// En función de la paleta, defino el color a devolver.
switch (PaletaInterfaz.Paleta)
{
case PaletaInterfaz.Tipo_Paleta.Oscura: return Oscura_Texto;
case PaletaInterfaz.Tipo_Paleta.Original:
default: return Original_Texto;
}
}
}