Silverlight 2:Silverlight 2 中的 XamlParseException
我在 Silverlight 2 中出现以下问题;在 Silverlight 3 中,相同的代码可以正常工作。
XAML代码如下:
<UserControl x:Class="My_Discussions.ThreadListItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:discussion="clr-namespace:My_Discussions"
Width="Auto" Height="Auto">
<UserControl.Resources>
<ControlTemplate x:Key="TopicItem">
<Grid x:Name="TopicItemHost" ShowGridLines="False" Margin="0,8" VerticalAlignment="Stretch">
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal" />
<vsm:VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="hotRect"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="TopicItemHost"
Storyboard.TargetProperty="Cursor"
Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Cursors>Hand</Cursors>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:Name="FocusStates">
<vsm:VisualState x:Name="Unfocused" />
<vsm:VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="focusRect"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:Name="ReadUnreadStates">
<vsm:VisualState x:Name="Read" />
<vsm:VisualState x:Name="Unread">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="TopicTitle"
Storyboard.TargetProperty="FontWeight"
Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<FontWeight>Bold</FontWeight>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle x:Name="focusRect" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="2" Fill="#F0F0F0" Margin="0,-8" Opacity="0"/>
<Rectangle x:Name="hotRect" Grid.Column="1" Height="1" Margin="0,0,0,0" VerticalAlignment="Bottom" Opacity="0"
>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#4080C0" Offset="0" />
<GradientStop Color="Gray" Offset="0.5" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="TopicLock" Grid.Column="0" Visibility="Collapsed"
Stretch="None" Source="Images/locked.png" Margin="10,2,10,0"
VerticalAlignment="Top" />
<discussion:ThreadListItemTitleHost Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Stretch">
<discussion:TextCut x:Name="TopicTitle"
Padding="0,0"
Foreground="#4080C0"
HorizontalAlignment="Left"
VerticalAlignment="Top"/>
<discussion:TextCut x:Name="TopicBody"
Padding="4,0"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Foreground="Gray"/>
</discussion:ThreadListItemTitleHost>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ProjectItem">
<TextBlock x:Name="Project" Padding="10,8" VerticalAlignment="Top" TextWrapping="Wrap"/>
</ControlTemplate>
<ControlTemplate x:Key="MessagesItem">
<TextBlock x:Name="Messages" Padding="10,8" VerticalAlignment="Top"/>
</ControlTemplate>
<ControlTemplate x:Key="AuthorItem">
<discussion:TextCut x:Name="Author" Padding="10,8" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
</ControlTemplate>
<ControlTemplate x:Key="DateItem">
<TextBlock x:Name="Date" Padding="10,8" VerticalAlignment="Top" />
</ControlTemplate>
<ControlTemplate x:Key="BottomBorder">
<Rectangle Width="Auto" Height="0.5" VerticalAlignment="Bottom" Stroke="Gray" StrokeThickness="0.5" />
</ControlTemplate>
</UserControl.Resources>
因此,XAML 中有一个名为“TopicTitle”的控件。实现该控件的类 TextCut 包含属性“FontWeight”:
public static readonly DependencyProperty FontWeightProperty = DependencyProperty.RegisterAttached(
"FontWeight",
typeof(FontWeight),
typeof(TextCut),
new PropertyMetadata(new PropertyChangedCallback(OnFontWeightPropertyChanged)));
然后我调用“VisualStateManager.GoToState(ctrl, "Unread", false)”。此调用应将值 Bold 设置为控件“TopicTitle”的属性“FontWeight”。
在 Silverlight 2.0 上,会发生以下异常:
XamlParseException: 行号: 0 线路位置:0 消息:“[行:0 位置:0]” 调用堆栈是: MS.Internal.XcpImports.CheckHResult(UInt32 小时) 在 MS.Internal.XcpImports.Storyboard_SeekAlignedToLastTick(故事板情节提要,单次搜索时间) 在 System.Windows.Media.Animation.Storyboard.SeekAlignedToLastTick(时间跨度偏移) 在 System.Windows.VisualStateGroup.StartNewThenStopOld(FrameworkElement 元素,Storyboard[] newStoryboards) 在 System.Windows.VisualStateManager.GoToStateInternal(控制控件、FrameworkElement 元素、VisualStateGroup 组、VisualState 状态、布尔 useTransitions) 在 System.Windows.VisualStateManager.GoToState(Control control, String stateName, Boolean useTransitions)
在 Silverlight 3.0 上,正如我所说,没有问题。问题是:Silverlight 2.0 上会发生什么以及如何避免这种情况?什么是“[Line:0 Position:0]” - 它对我什么也没告诉。
I have the following problem that appears in Silverlight 2; in Silverlight 3 the same code works OK.
The XAML code is the following:
<UserControl x:Class="My_Discussions.ThreadListItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:discussion="clr-namespace:My_Discussions"
Width="Auto" Height="Auto">
<UserControl.Resources>
<ControlTemplate x:Key="TopicItem">
<Grid x:Name="TopicItemHost" ShowGridLines="False" Margin="0,8" VerticalAlignment="Stretch">
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualState x:Name="Normal" />
<vsm:VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="hotRect"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="TopicItemHost"
Storyboard.TargetProperty="Cursor"
Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Cursors>Hand</Cursors>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:Name="FocusStates">
<vsm:VisualState x:Name="Unfocused" />
<vsm:VisualState x:Name="Focused">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="focusRect"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
<vsm:VisualStateGroup x:Name="ReadUnreadStates">
<vsm:VisualState x:Name="Read" />
<vsm:VisualState x:Name="Unread">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="TopicTitle"
Storyboard.TargetProperty="FontWeight"
Duration="0">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<FontWeight>Bold</FontWeight>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</vsm:VisualState>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle x:Name="focusRect" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="2" Fill="#F0F0F0" Margin="0,-8" Opacity="0"/>
<Rectangle x:Name="hotRect" Grid.Column="1" Height="1" Margin="0,0,0,0" VerticalAlignment="Bottom" Opacity="0"
>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Color="#4080C0" Offset="0" />
<GradientStop Color="Gray" Offset="0.5" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="TopicLock" Grid.Column="0" Visibility="Collapsed"
Stretch="None" Source="Images/locked.png" Margin="10,2,10,0"
VerticalAlignment="Top" />
<discussion:ThreadListItemTitleHost Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Stretch">
<discussion:TextCut x:Name="TopicTitle"
Padding="0,0"
Foreground="#4080C0"
HorizontalAlignment="Left"
VerticalAlignment="Top"/>
<discussion:TextCut x:Name="TopicBody"
Padding="4,0"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Foreground="Gray"/>
</discussion:ThreadListItemTitleHost>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ProjectItem">
<TextBlock x:Name="Project" Padding="10,8" VerticalAlignment="Top" TextWrapping="Wrap"/>
</ControlTemplate>
<ControlTemplate x:Key="MessagesItem">
<TextBlock x:Name="Messages" Padding="10,8" VerticalAlignment="Top"/>
</ControlTemplate>
<ControlTemplate x:Key="AuthorItem">
<discussion:TextCut x:Name="Author" Padding="10,8" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
</ControlTemplate>
<ControlTemplate x:Key="DateItem">
<TextBlock x:Name="Date" Padding="10,8" VerticalAlignment="Top" />
</ControlTemplate>
<ControlTemplate x:Key="BottomBorder">
<Rectangle Width="Auto" Height="0.5" VerticalAlignment="Bottom" Stroke="Gray" StrokeThickness="0.5" />
</ControlTemplate>
</UserControl.Resources>
So, there is a control named "TopicTitle" in the XAML. Class TextCut that implements the control contains property "FontWeight":
public static readonly DependencyProperty FontWeightProperty = DependencyProperty.RegisterAttached(
"FontWeight",
typeof(FontWeight),
typeof(TextCut),
new PropertyMetadata(new PropertyChangedCallback(OnFontWeightPropertyChanged)));
Then I call "VisualStateManager.GoToState(ctrl, "Unread", false)". This call should set value Bold into property "FontWeight" of the control "TopicTitle".
On Silverlight 2.0 the following exception happens:
XamlParseException:
LineNumber: 0
LinePosition: 0
Message: "[Line:0 Position:0]"
The call stack was:
MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Storyboard_SeekAlignedToLastTick(Storyboard storyboard, Single seekTime)
at System.Windows.Media.Animation.Storyboard.SeekAlignedToLastTick(TimeSpan offset)
at System.Windows.VisualStateGroup.StartNewThenStopOld(FrameworkElement element, Storyboard[] newStoryboards)
at System.Windows.VisualStateManager.GoToStateInternal(Control control, FrameworkElement element, VisualStateGroup group, VisualState state, Boolean useTransitions)
at System.Windows.VisualStateManager.GoToState(Control control, String stateName, Boolean useTransitions)
On Silverlight 3.0, as I said, there are no problems. The question is: what happens on Silverlight 2.0 and how can avoid this? What is the "[Line:0 Position:0]" - it tells nothing to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我的 Silverlight 2 知识相当生疏,但看看调用堆栈,我会说它对此感到不安:-
我确信您一定有充分的理由坚持使用 SL2,但我忍不住说这可能是解决办法就是用SL3。
Well my Silverlight 2 knowledge is quite rusty but looking at the call stack I'd say its getting upset by this:-
I'm sure you must have good reasons for sticking with SL2 but I can't help stating that may be the fix is to use SL3.