昨天用到Silverlight Slider控件,预览时却报错!是因为在XAML中设置了它的Value属性值之后,才报的错,
所以一下子定位到XAML中Value值的设置上。于是用 Minimum、Maximum、中间值赋给Value测了下,还是出现同样的问题!
把Value属性从中删除,竟然一切正常。怪事了!
是不是受到了代码中其他控件的影响?于是今天特意新建了个项目,就单独使用Slider控件,重复前天的操作,问题重现!
以下贴上代码:
Page.xaml
1
<UserControl x:Class="SliderMaxValueTest.Page"
2
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
Width="400" Height="300">
5
<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
6
<Grid.RowDefinitions>
7
<RowDefinition Height="150" />
8
<RowDefinition Height="*" />
9
</Grid.RowDefinitions>
10
<Slider Maximum="255" Minimum="0" Value="100.0" Grid.Row="0" x:Name="sld" Orientation="Vertical" MaxHeight="300" ValueChanged="Slider_ValueChanged"/>
11
<TextBlock x:Name="Val" Grid.Row="1" Width="200" />
12
</Grid>
13
</UserControl>
Page.xaml.cs
1
namespace SliderMaxValueTest
2
{
3
public partial class Page : UserControl
4
{
5
public Page()
6
{
7
InitializeComponent();
8
}
9
10
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
11
{
12
Val.Text = e.NewValue.ToString();
13
}
14
}
15
}
预览测试网页文件时报错:
Microsoft JScript runtime error: Unhandled Error in Silverlight 2 Application AG_E_PARSER_BAD_PROPERTY_VALUE [Line: 10 Position: 157] at System.Windows.Application.LoadComponent(Object component, Uri xamlUri)
at SliderMaxValueTest.Page.InitializeComponent()
at SliderMaxValueTest.Page..ctor()
at SliderMaxValueTest.App.Application_Startup(Object sender, StartupEventArgs e)
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
到底出了啥问题?是Silverlight的版本Bug问题?还是其他?
上了博问提问了下,有幸得到TerryLee的回答:
“在Silverlight 2 Beta 2中,如果定义了ValueChanged,似乎不能给Slider的value属性在Xaml中赋初值,可能是一个Bug。”
他用了“可能”这个词,但谢谢他让我知道了引起问题的原因:“如果定义了ValueChanged,。。。”
刚加入的cnblog,这是写的第一篇随笔,就以这个bug开始吧:)

