当在xaml文件中设置Value值之后,编译解决方案后 预览时会报错!~~具体代码如下: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
1namespace SliderMaxValueTest 2{ 3 public partial class Page : UserControl 4 { 5 public Page() 6 { 7 InitializeComponent(); 8 } 910 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)如果不设置 Slider 控件的Value值时,就很正常!很是纳闷,哪位朋友帮我看下错哪了?难道是Silverlight版本问题?
1 回答
狐的传说
TA贡献1804条经验 获得超3个赞
在Silverlight 2 Beta 2中,如果定义了ValueChanged,似乎不能给Slider的value属性在Xaml中赋初值,可能是一个Bug。
你可以在Page的构造函数中:
public Page()
{
InitializeComponent();
this.sld.Value = 100;
}
或者在Page_Loaded事件中赋初值:
void Page_Loaded(object sender, RoutedEventArgs e)
{
this.sld.Value = 100;
}
- 1 回答
- 0 关注
- 424 浏览
添加回答
举报
0/150
提交
取消