当在xaml文件中设置Value值之后,编译解决方案后 预览时会报错
具体代码如下:
Page.xaml
具体代码如下:
Page.xaml
<UserControl x:Class="SliderMaxValueTest.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="150" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Slider Maximum="255" Minimum="0" Value="100.0" Grid.Row="0" x:Name="sld" Orientation="Vertical" MaxHeight="300" ValueChanged="Slider_ValueChanged"/>
<TextBlock x:Name="Val" Grid.Row="1" Width="200" />
</Grid>
</UserControl>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="150" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Slider Maximum="255" Minimum="0" Value="100.0" Grid.Row="0" x:Name="sld" Orientation="Vertical" MaxHeight="300" ValueChanged="Slider_ValueChanged"/>
<TextBlock x:Name="Val" Grid.Row="1" Width="200" />
</Grid>
</UserControl>
Page.xaml.cs
namespace SliderMaxValueTest
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Val.Text = e.NewValue.ToString();
}
}
}
namespace SliderMaxValueTest
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Val.Text = e.NewValue.ToString();
}
}
}
解决办法:
在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;
}
在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;
}