我如何在代码中知道RadialGradientBrush是否未正确显示? [英] How do I know, in code, if RadialGradientBrush is not being shown correctly?
问题描述
我将RadialGradientBrush用作Button的背景. 在一台计算机上,它运行良好. 另一方面,背景是透明的.
I'm using RadialGradientBrush as background for a Button. On one computer, it works well. On the other, the background is transparent.
NewComputer:Intel i7-8700、16Gb ram,64位操作系统,图形-Nvidia GeForce GTx1050Ti
NewComputer: Intel i7-8700, 16Gb ram, 64-bit OS, graphics - Nvidia GeForce GTx1050Ti
OldComputer:Intel 6300、2Gb ram,32位操作系统,图形-Intel G965 Express芯片组家族
OldComputer: Intel 6300, 2Gb ram, 32-bit OS, graphics - Intel G965 Express Chipset Family
两台计算机都运行Windows 10 Home,1809(17763.503),1920x1080显示器.
Both computers are running Windows 10 Home, 1809 (17763.503), 1920x1080 monitor.
在每台计算机上运行相同的程序(如下所示),我没有让RadialGradientBrush显示在OldComputer上. RadialGradientBrush处于活动状态-我可以从GradientStop 1 中获取颜色,并将其用作用于背景的SolidColorBrush.
Running the same program on each computer (shown below), I do not get the RadialGradientBrush to show up on the OldComputer. The RadialGradientBrush is active - I can get the color from GradientStop1, and use that as a SolidColorBrush for the background.
LinearGradientBrush将正确显示在OldComputer上.
A LinearGradientBrush will show up correctly on the OldComputer.
G965的驱动程序从2012年开始,是最新的驱动程序.我猜是问题出在旧的G965图形上,尽管我对此并不满意.
The driver for the G965 is from 2012, which is as up-to-date as is available. I am guessing that the problem is this old G965 graphics, though I am not positive of this.
这是程序中唯一的代码.除了默认的代码外,没有其他任何代码.
This is the only code in the program. There is no additional code behind, other than that which comes as default.
<Page
x:Class="RadialGradientBrush_Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RadialGradientBrush_Test"
xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<!-- Radial Brush -->
<media:RadialGradientBrush x:Key="MyRadialBrush"
GradientOrigin="0.5,0.5" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5" FallbackColor="Red">
<GradientStop Color="#FFF0F8FF" Offset="0" />
<GradientStop Color="#FF1E90FF" Offset="1" />
</media:RadialGradientBrush>
</Page.Resources>
<Grid>
<Button Content="Test" Background="{StaticResource MyRadialBrush}"
HorizontalAlignment="Center" BorderBrush="Black"
BorderThickness="1"/>
</Grid>
</Page>
NewComputer:
NewComputer:
OldComputer:
OldComputer:
我有一种解决方法,该方法是在按钮后面放置一个边框,该边框与按钮的形状相同,并用后备纯色填充.
I have a workaround, which is putting a border behind the button, with the same shape as the button, filled with the fallback solid color.
我宁愿在代码中找到一种方法来知道是否要显示RadialGradientBrush,然后将按钮背景更改为SolidColorBrush,也许是看图形系统的功能?
从概念上讲,类似于Graphics.Capabilities.RadialGradientBrush.
有什么想法要怎么做?
I would rather find a way in code to know if the RadialGradientBrush is going to be shown, and then change the button background to a SolidColorBrush, maybe looking at the capabilities of the graphics system?
Conceptually, something like Graphics.Capabilities.RadialGradientBrush.
Any ideas how to do this?
在OldComputer中使用图形卡-现在可以显示RadialGradientBrush.似乎是G965图形. 我使用WindowsCommunityToolkit在此问题上提出了问题.
Edit 1: Using a graphics card in the OldComputer - can now display RadialGradientBrush. Appears to be the G965 graphics. I opened an issue on this with WindowsCommunityToolkit.
推荐答案
我宁愿在代码中找到一种方法来知道是否要显示RadialGradientBrush,然后将按钮背景更改为SolidColorBrush,也许是看图形系统的功能?
I would rather find a way in code to know if the RadialGradientBrush is going to be shown, and then change the button background to a SolidColorBrush, maybe looking at the capabilities of the graphics system?
RadialGradientBrush 类具有
The RadialGradientBrush class has a FallbackColor
property. The color to use for rendering in case the CompositionBrush can't be rendered. It meets your requirement.
<media:RadialGradientBrush x:Key="MyRadialBrush"
GradientOrigin="0.5,0.5" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5" FallbackColor="White">
<GradientStop Color="#FFF0F8FF" Offset="0" />
<GradientStop Color="#FF1E90FF" Offset="1" />
</media:RadialGradientBrush>
这篇关于我如何在代码中知道RadialGradientBrush是否未正确显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!