一个奇怪的bug
2018-02-01 15:14
513 查看
最近在完成一个项目,说白了也就是一个在win7上运行的沙盒程序。于是采用WPF + SurfaceSDK实现相应的功能。使用了WPF原生的Button等控件,可是到了客户机上运行时候控件的样式总是不是非常理想。后来发现是开发环境和运行环境的Windows主题不同造成的问题,所以准备自己写一些控件,这个时候就出现了这个奇怪的问题,在此记录,如有能够“正确解决”的朋友,欢迎留言讨论。
错误描述: “{DependencyProperty.UnsetValue}”不是 Setter 上“System.Windows.Controls.Border.BorderBrush”属性的有效值
详细图片如下:
项目目录如下:
App.xaml
Dictionary1.xaml
MainWindow.xaml
MainWindow.cs
就是Dictionary1.xaml内部注释掉的代码,使用静态资源会报错。即不能使用静态资源去实现,只能使用固定的值。
错误描述: “{DependencyProperty.UnsetValue}”不是 Setter 上“System.Windows.Controls.Border.BorderBrush”属性的有效值
详细图片如下:
项目目录如下:
App.xaml
<Application x:Class="WpfApplication_MyButton.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Dictionary1.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
Dictionary1.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!--自定义颜色--> <LinearGradientBrush x:Key="LinearGradientBlueBackground" EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FF377FED" Offset="0" /> <GradientStop Color="#FF074CC0" Offset="1" /> </LinearGradientBrush> <!--<Color x:Key="MyBtnHoverBackgroundColor" >#000000</Color>--> <!--END--> <Style x:Key="MyWpfButton" TargetType="{x:Type Button}" > <Setter Property="Background" Value="{StaticResource LinearGradientBlueBackground}"></Setter> <Setter Property="Foreground" Value="White"></Setter> <Setter Property="BorderBrush" Value="#000000"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" CornerRadius="3,3,3,3"> <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="true"> <!--此处使用静态调用会报错误,必须使用具体的值才行--> <!--<Setter Property="Background" TargetName="border" Value="{StaticResource MyBtnHoverBackgroundColor}"/>--> <Setter Property="Background" TargetName="border" Value="Red"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
MainWindow.xaml
<Window x:Class="WpfApplication_MyButton.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="Button1" Style="{StaticResource ResourceKey=MyWpfButton}" Height="40" Width="100" Margin="217,40,186,232"></Button> <Button Content="Button2" HorizontalAlignment="Left" Height="40" Width="100" Margin="34,39,0,232"></Button> </Grid> </Window>
MainWindow.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication_MyButton { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } } }
就是Dictionary1.xaml内部注释掉的代码,使用静态资源会报错。即不能使用静态资源去实现,只能使用固定的值。
相关文章推荐
- pyqt4的qwebpage一个奇怪的bug
- 9a96 OkHttp的一个奇怪的bug
- 'xxx' declared as a 'virtual' field ----一个奇怪的C++bug
- 一个奇怪BUG的记录(未根本解决)
- Delphi 7 的一个奇怪的Bug
- 一个奇怪的bug
- 今天发现一个非常奇怪的VSIDE BUG,经过1个小时的研究解决
- 一个MySQL的奇怪问题-----不知道算不算bug
- JWFD工作流设计器一个奇怪的BUG
- 一个奇怪的bug
- MySQL创建过程,遇到一个奇怪的bug
- 关于google的gson-2.3.1.jar,发现一个奇怪的bug
- 一个失误引发的奇怪线程BUG
- [原创]发现QQ截图功能的一个奇怪bug(不能选择保存文件类型)
- cocos2dx项目在android平台第一次安装的一个奇怪的bug
- 苹果浏览器CSS一个奇怪的BUG
- spark一个奇怪的bug
- J2ME中一个奇怪的BUG及其解决方法
- VC7.1的一个奇怪的bug
- 一个奇怪的Bug“Unable to create application ”