我正在创建一些包含应用程序所有样式的wpf资源字典!我有一些LinearGradientBrushes,其中颜色直接在L inearGradientBrush参考中设置为GradientStops.但是,我希望有一组预定义的颜色,我可以为每个颜色使用一个引用GradientStop,这样更改应用程序的颜色方案就是更改SolidColorBrushes 的值:
<SolidColorBrush Color="#5A5A5A" x:Key="colorbrushMedium" />
<SolidColorBrush Color="#222222" x:Key="colorbrushDark" />
<LinearGradientBrush>
<GradientStop Color="{StaticResource colorbrushMedium}"/>
<GradientStop Color="{StaticResource colorbrushDark}" Offset="1"/>
</LinearGradientBrush>
Run Code Online (Sandbox Code Playgroud)
使用上面的代码示例,我收到以下错误:
Cannot convert the value in attribute 'Color' to object of type 'System.Windows.Media.Color'. '#5A5A5A' is not a valid value for property 'Color'.
Run Code Online (Sandbox Code Playgroud)
它引用的行<GradientStop Color="{StaticResource colorbrushMedium}"/>是定义的行.
有任何想法吗?
我正在寻找一种Brush在Brushes集合中随机选择的方法(Aqua,Azure,... Black,...).任何线索?
在WPF中,我可以使用以下代码设置堆栈面板的背景
stackPanelFlasher.Background = Brushes.Aqua;
Run Code Online (Sandbox Code Playgroud)
例如,如何将颜色设置为十六进制颜色代码#C7DFFC?
下面是Conway在WPF中的生命游戏的一个(非常天真)实现.这只是一个演示......
XAML:
<Window x:Class="wpf_conway_life_2013_05_19.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="500">
<Grid>
<Canvas Name="canvas"
Width="auto"
Height="auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
</Canvas>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
代码背后:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace wpf_conway_life_2013_05_19
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var random = new Random();
var data = new int[100, 100];
var dataB = new int[100, 100];
Func<int, int, int> at = (x, y) =>
{
if (x < 0) x = 100 + …Run Code Online (Sandbox Code Playgroud) 也许我有一个后Ballmer-Peak时刻.我希望有人可以向我指出明显的问题.
为什么此代码在右键单击时生成上下文菜单:
<Canvas Background="Transparent">
<Canvas.ContextMenu>
<ContextMenu>
<TextBlock>WTF?</TextBlock>
</ContextMenu>
</Canvas.ContextMenu>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
并且此代码不会生成上下文菜单:
<Canvas>
<Canvas.ContextMenu>
<ContextMenu>
<TextBlock>WTF?</TextBlock>
</ContextMenu>
</Canvas.ContextMenu>
</Canvas>
Run Code Online (Sandbox Code Playgroud) 我有一个刷子,用于为标题的背景着色.我喜欢画笔的外观,但希望它在底部三分之一处淡出透明.任何想法如何做到这一点?
<LinearGradientBrush
x:Key="HeaderBackgroundBrush"
EndPoint=".5,1"
StartPoint="1,0">
<GradientStop Color="#006699" Offset="1"/>
<GradientStop Color="#80A8CC" Offset="0.5"/>
</LinearGradientBrush>
Run Code Online (Sandbox Code Playgroud) 我们公司正在开发的一个应用程序目前显示许多带有渐变的矩形形状来绘制"Tiles".内部讨论提出了一个表现问题.这些图块大约为100像素乘200像素,并且是渐变阴影红色,黄色或绿色.在任何给定时间,屏幕上最多可以有100个这样的图块.难道是更好的性能,我们为每个创建的图像(红,黄,绿),并在必要时重复它,或者它会更好,我们继续使用标准WPF画笔绘制呢?
编辑:为了澄清,我们使用的渐变画笔是LinearGradientBrush.
没有一个叫做Pens,这是肯定的,但是找不到它太奇怪了.它真的缺席了,还是我失明了?
(我只是在寻找一个方便的类-例如,Colors.Red并且Brushes.Red是存在的,但对于笔最短似乎是new Pen(Brushes.Red, 1))
我有一个属性,允许将已知颜色的字符串名称发送到我的控件.酒店仅接受正确的已知颜色名称,如"红色"或"蓝色"
private KnownColor _UseColor = KnownColor.Red;
/// <summary>
/// Gets or sets the name of the colour
/// </summary>
public string ColorName
{
get
{
return this._UseColor.ToString();
}
set
{
if (Enum.IsDefined(typeof(KnownColor), value))
this._UseColour = (KnownColor)Enum.Parse(typeof(KnownColor), value);
}
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是使用这个_UseColour枚举从.NET中的静态Brushes类中选择一个现有的画笔
Brush sysBrush = Brushes.FromKnownColor(this._UseColor);
e.Graphics.FillRectangle(sysBrush, 0, 0, 10, 10);
Run Code Online (Sandbox Code Playgroud)
而不是在控件被绘制时创建一个新的画笔
using (SolidBrush brsh = new SolidBrush(Color.FromKnownColor(this._UseColor)))
e.Graphics.FillRectangle(brsh, 0, 0, 10, 10);
Run Code Online (Sandbox Code Playgroud)
有谁知道这是否可能,或者我每次都要创建一个新画笔?
Brushes.FromKnownColor不是Brushes班上的方法
我想用画笔绘制透明区域,但我的代码工作得不是很好.我想有人可以帮助我.我的代码:
// Handles the start of a touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch *touch = [[event touchesForView:self] anyObject];
if (![image isPointTransparent:[touch locationInView:self]]
|| ![image isPointTransparent:[touch previousLocationInView:self]])
{
return;
}
firstTouch = YES;
// Convert touch point from UIView referential to OpenGL one (upside-down flip)
location = [touch locationInView:self];
location.y = bounds.size.height - location.y;
}
// Handles the continuation of a touch.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect bounds = [self bounds];
UITouch …Run Code Online (Sandbox Code Playgroud) 我是WPF的新手,仍然有一些基本问题.
我有一个来自devcomponents的控件,默认为蓝色边框.我的文本框等具有更灰色的颜色.我希望devcomponents控件具有相同的边框.
我查看TextBox的属性,看看BorderBrush设置为"System.Windows.Media.LinearGradientBrush"但我不能放 -
<WpfEditors:IntegerInput BorderBrush="System.Windows.Media.LinearGradientBrush"...
Run Code Online (Sandbox Code Playgroud)
事实上,我不能把 -
<TextBox BorderBrush="System.Windows.Media.LinearGradientBrush" ...
Run Code Online (Sandbox Code Playgroud)
我错过了什么魔法?
谢谢.
我正在尝试使用WPF中的颜色和表单的背景颜色.没有做任何事情(没有代码,从另一个类派生等),我创建了一个全新的默认Windows窗体.我将背景更改为浅蓝色.保存表单.运行该程序并打开该表单..表单显示在一些其他更深的颜色,如它甚至不尊重XAML
<Window x:Class="MyProjectNamespace.AnotherWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="AnotherWindow" Height="300" Width="300" Background="#4800A8A6">
<Grid>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
另外,如果我尝试使用#4800A8A6的相同背景值并尝试创建画笔并执行BrushConverter.ConvertFrom("#4800A8A6"); 然后运行表单,我仍然得到设计师显示的不正确的颜色......是什么给...
我有一个LinearGradientBrush定义如下.我想在我的xaml中使用它,但我想在这种特殊情况下改变不透明度(仅在这种情况下,不是我使用它的任何地方).任何想法如何实现这一目标?
<LinearGradientBrush x:Key="BlueBackgroundBrush" EndPoint="0.874,1.197" StartPoint="0.126,-0.197">
<GradientStop Color="#1954B2" />
<GradientStop Color="#1954B2" Offset="0.982" />
<GradientStop Color="#FF84B2D4" Offset="0.304" />
</LinearGradientBrush>
Run Code Online (Sandbox Code Playgroud) brushes ×13
wpf ×11
c# ×7
.net ×2
colors ×2
xaml ×2
background ×1
brush ×1
color-codes ×1
gradient ×1
graphics ×1
image ×1
ios ×1
iphone ×1
objective-c ×1
performance ×1
rendering ×1
resources ×1
uiimageview ×1