- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我花了一整天的时间试图弄清楚为什么这个用户控件会导致 VS2010(Windows Phone 7.1 开发)崩溃。应用程序运行此控件没有问题,但当我进入 MainPage.xaml 中的设计模式时 - VS 崩溃。
<UserControl x:Class="blabla.Controls.Tile"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}">
<UserControl.Resources>
<Storyboard x:Name="SwitchSidesAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="FrontSide">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="90"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause1" KeyTime="0:0:6" Value="-90"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause2" KeyTime="0:0:6.2" Value="-90"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause3" KeyTime="0:0:6.4" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause4" KeyTime="0:0:12" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationX)" Storyboard.TargetName="BackSide">
<EasingDoubleKeyFrame KeyTime="0" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-90"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause5" KeyTime="0:0:6" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause6" KeyTime="0:0:6.2" Value="90"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause7" KeyTime="0:0:6.4" Value="90"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause8" KeyTime="0:0:12" Value="90"/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="FrontSide">
<DiscreteObjectKeyFrame KeyTime="0:0:0.2">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.4">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame x:Name="MoveThisForPause9" KeyTime="0:0:6">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame x:Name="MoveThisForPause10" KeyTime="0:0:6.4">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame x:Name="MoveThisForPause11" KeyTime="0:0:12">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="FrontSide">
<EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause12" KeyTime="0:0:6" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause13" KeyTime="0:0:6.2" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause14" KeyTime="0:0:6.4" Value="0"/>
<EasingDoubleKeyFrame x:Name="MoveThisForPause15" KeyTime="0:0:12" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<!-- Front side -->
<Grid x:Name="FrontSide" Grid.Column="0" Grid.Row="0"
Background="{Binding FrontBackground}">
<Image Source="{Binding FrontImage}" />
</Grid>
<!-- /Front side -->
<!-- Back side -->
<Grid x:Name="BackSide" Grid.Column="0" Grid.Row="0"
Background="{Binding BackBackground}">
<Grid.Projection>
<PlaneProjection RotationX="-90" />
</Grid.Projection>
<Image Source="{Binding BackImage}" />
</Grid>
<!-- /Back side -->
</Grid>
</UserControl>
现在是代码。
namespace blabla.Controls
{
public partial class Tile : UserControl
{
/// <summary>
/// Defines if the tile has two sides.
/// </summary>
public bool IsTwoSided
{
get { return (bool)GetValue(IsTwoSidedProperty); }
set
{
SetValue(IsTwoSidedProperty, value);
this.startAnimations();
}
}
/// <summary>
/// Image that will be displayed on front side.
/// </summary>
public BitmapImage FrontImage
{
get { return (BitmapImage)GetValue(FrontImageProperty); }
set { SetValue(FrontImageProperty, value); }
}
/// <summary>
/// Image that ill be displayed on back side.
/// </summary>
public BitmapImage BackImage
{
get { return (BitmapImage)GetValue(BackImageProperty); }
set { SetValue(BackImageProperty, value); }
}
/// <summary>
/// Brush that will be used as background for front side.
/// </summary>
public Brush FrontBackground
{
get { return (Brush)GetValue(FrontBackgroundProperty); }
set { SetValue(FrontBackgroundProperty, value); }
}
/// <summary>
/// Brush that will be used as background for back side.
/// </summary>
public Brush BackBackground
{
get { return (Brush)GetValue(BackBackgroundProperty); }
set { SetValue(BackBackgroundProperty, value); }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
public static readonly DependencyProperty IsTwoSidedProperty =
DependencyProperty.Register("IsTwoSided", typeof(bool), typeof(Tile), new PropertyMetadata(false));
public static readonly DependencyProperty FrontImageProperty =
DependencyProperty.Register("FrontImage", typeof(BitmapImage), typeof(Tile), new PropertyMetadata(null));
public static readonly DependencyProperty BackImageProperty =
DependencyProperty.Register("BackImage", typeof(BitmapImage), typeof(Tile), new PropertyMetadata(null));
public static readonly DependencyProperty FrontBackgroundProperty =
DependencyProperty.Register("FrontBackground", typeof(Brush), typeof(Tile),
new PropertyMetadata(new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"])));
public static readonly DependencyProperty BackBackgroundProperty =
DependencyProperty.Register("BackBackground", typeof(Brush), typeof(Tile),
new PropertyMetadata(new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"])));
///////////////////////////////////////////////////////////////////////////////////////////////////////
public Tile()
{
InitializeComponent();
this.LayoutRoot.DataContext = this;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary>
/// Modifies animation frames' KeyTime to adjust time for new timing.
/// <param name="pauseTime">Lenght of the pause.</param>
/// </summary>
private void setPauses(TimeSpan pauseTime)
{
// Sets pauses.
EasingDoubleKeyFrame frameToModify;
for(int i = 0; true; i++)
{
if(this.FindName("MoveThisForPause" + i) != null)
{
frameToModify = (EasingDoubleKeyFrame)this.FindName("MoveThisForPause" + i);
frameToModify.KeyTime = KeyTime.FromTimeSpan(frameToModify.KeyTime.TimeSpan - TimeSpan.FromSeconds(5) + pauseTime);
}
else
{
break;
}
}
}
/// <summary>
/// Starts animations.
/// </summary>
/// <param name="beginTime">Usually delay before first-time animation.</param>
private void startAnimations()
{
// We start animations only if the tile is two sided.
if(this.IsTwoSided)
{
// Stopping previous animation.
this.SwitchSidesAnimation.Stop();
// Sets correct pauses.
this.setPauses(TimeSpan.FromSeconds(new Random().Next(5, 10)));
// Starts animation.
this.SwitchSidesAnimation.BeginTime = TimeSpan.FromSeconds(new Random().Next(2, 15));
this.SwitchSidesAnimation.RepeatBehavior = RepeatBehavior.Forever;
this.SwitchSidesAnimation.Begin();
}
else
{
this.SwitchSidesAnimation.Stop();
}
}
}
}
最佳答案
我已经能够重现此崩溃,诚然使用非电话版本的 Silverlight,并且在 Visual Web Dev Express 中而不是完整版本的 VS。
问题最终归结为这两个依赖属性声明中指定的默认值:
public static readonly DependencyProperty FrontBackgroundProperty =
DependencyProperty.Register("FrontBackground", typeof(Brush), typeof(Tile),
new PropertyMetadata(new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"])));
public static readonly DependencyProperty BackBackgroundProperty =
DependencyProperty.Register("BackBackground", typeof(Brush), typeof(Tile),
new PropertyMetadata(new SolidColorBrush((Color)Application.Current.Resources["PhoneAccentColor"])));
在我用 null
替换默认值后,崩溃消失了(使用 Notepad++ 作为 Visual Web Dev Express 崩溃),删除了项目的 bin
和 obj
文件夹并重新启动 Visual Web Dev Express。当我重新启动 VWDX 时,它提示找不到类型 Tile
, 但那是因为我删除了 bin
和 obj
文件夹。重建解决了这个问题。
我只能猜测究竟是什么问题。在 Tile
点正在静态初始化类,Application.Current
可能是 null
, Application.Current.Resources
可能是 null
, 或 Application.Current.Resources["PhoneAccentColor"]
可能是 null
(这会导致转换为 Color
失败,因为 Color
是 struct
)。可能 VS 设计者没有很好地处理在类型的静态初始化期间抛出的异常?
顺便说一下,我还想指出另外几个潜在的问题。首先,这是您的 IsTwoSided
属性:
/// <summary>
/// Defines if the tile has two sides.
/// </summary>
public bool IsTwoSided
{
get { return (bool)GetValue(IsTwoSidedProperty); }
set
{
SetValue(IsTwoSidedProperty, value);
this.startAnimations();
}
}
看起来你想要 startAnimations
每当您的 IsTwoSided
时调用的方法依赖属性更改。您在上面编写的代码不会实现这一点。
当 Silverlight 更改依赖属性的值时,它不会调用您的属性 setter 来执行此操作。如果您希望在依赖属性的值更改时发生某些事情,请使用 property-changed callback相反。
其次,在Tile.xaml
, 你声明 Storyboard
在<UserControl.Resources>
如下:
<Storyboard x:Name="SwitchSidesAnimation">
我建议使用 x:Key
而不是 x:Name
,有两个原因:
资源字典中的所有项目(隐式样式除外)必须具有 x:Key
或 x:Name
识别他们。 VS 支持使用 x:Name
代替 x:Key
, 但它以 legacy support mechanism 的形式存在仅。
使用 x:Name
在用户控件的元素中 XAML 导致 VS 在 InitializeComponent()
中创建一个具有该名称的字段在您的 Tile
的自动生成部分类(在 obj\Debug 中的 Tile.g.cs
中)。然而,就因为你能坚持x:Name
在一个元素上并不一定意味着您将能够访问生成字段中的相应对象。因为没有名为 SwitchSidesAnimation
的 UIElement在你的Tile.xaml
( Storyboard不是 UIElements),SwitchSidesAnimation
字段将始终为 null
.
的确,MSDN documentation for the x:Key attribute (也链接到上面)提到
A FindName call using a key value will not retrieve a keyed resource
(FindName
是用于按名称查找控件的方法。如果您查看 Tile.g.cs
,您会看到它在那里使用。)
我建议始终使用 x:Key
在资源字典中,这样您就不会相信您可以直接在代码隐藏中访问这个 Storyboard。
要在代码隐藏中访问 Storyboard,请使用
this.Resources["SwitchSidesAnimation"] as Storyboard
事实上,如果您添加以下属性,则不必更改您的 startAnimations
方法:
private Storyboard SwitchSidesAnimation
{
get { return this.Resources["SwitchSidesAnimation"] as Storyboard; }
}
关于c# - 为什么我的用户控件会导致 Visual Studio 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11814466/
尝试使用集成到 QTCreator 的表单编辑器,但即使我将插件放入 QtCreator.app/Contents/MacOS/designer 也不会显示。不过,相同的 dylib 文件确实适用于独
在此代码示例中。 “this.method2();”之后会读到什么?在返回returnedValue之前会跳转到method2()吗? public int method1(int returnedV
我的项目有通过gradle配置的依赖项。我想添加以下依赖项: compile group: 'org.restlet.jse', name: 'org.restlet.ext.apispark', v
我将把我们基于 Windows 的客户管理软件移植到基于 Web 的软件。我发现 polymer 可能是一种选择。 但是,对于我们的使用,我们找不到 polymer 组件具有表格 View 、下拉菜单
我的项目文件夹 Project 中有一个文件夹,比如 ED 文件夹,当我在 Eclipse 中指定在哪里查找我写入的文件时 File file = new File("ED/text.txt"); e
这是奇怪的事情,这个有效: $('#box').css({"backgroundPosition": "0px 250px"}); 但这不起作用,它只是不改变位置: $('#box').animate
这个问题在这里已经有了答案: Why does OR 0 round numbers in Javascript? (3 个答案) 关闭 5 年前。 Mozilla JavaScript Guide
这个问题在这里已经有了答案: Is the function strcmpi in the C standard libary of ISO? (3 个答案) 关闭 8 年前。 我有一个问题,为什么
我目前使用的是共享主机方案,我不确定它使用的是哪个版本的 MySQL,但它似乎不支持 DATETIMEOFFSET 类型。 是否存在支持 DATETIMEOFFSET 的 MySQL 版本?或者有计划
研究 Seam 3,我发现 Seam Solder 允许将 @Named 注释应用于包 - 在这种情况下,该包中的所有 bean 都将自动命名,就好像它们符合条件一样@Named 他们自己。我没有看到
我知道 .append 偶尔会增加数组的容量并形成数组的新副本,但 .removeLast 会逆转这种情况并减少容量通过复制到一个新的更小的数组来改变数组? 最佳答案 否(或者至少如果是,则它是一个错
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
noexcept 函数说明符是否旨在 boost 性能,因为生成的对象中可能没有记录异常的代码,因此应尽可能将其添加到函数声明和定义中?我首先想到了可调用对象的包装器,其中 noexcept 可能会产
我正在使用 Angularjs 1.3.7,刚刚发现 Promise.all 在成功响应后不会更新 angularjs View ,而 $q.all 会。由于 Promises 包含在 native
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我正在编写一个玩具(物理)矢量库,并且遇到了 GHC 坚持认为函数应该具有 Integer 的问题。是他们的类型。我希望向量乘以向量以及标量(仅使用 * ),虽然这可以通过仅使用 Vector 来实现
PHP 的 mail() 函数发送邮件正常,但 Swiftmailer 的 Swift_MailTransport 不起作用! 这有效: mail('user@example.com', 'test
我尝试通过 php 脚本转储我的数据,但没有命令行。所以我用 this script 创建了我的 .sql 文件然后我尝试使用我的脚本: $link = mysql_connect($host, $u
使用 python 2.6.4 中的 sqlite3 标准库,以下查询在 sqlite3 命令行上运行良好: select segmentid, node_t, start, number,title
我最近发现了这段JavaScript代码: Math.random() * 0x1000000 10.12345 10.12345 >> 0 10 > 10.12345 >>> 0 10 我使用
我是一名优秀的程序员,十分优秀!