Silverlight 运行时说缺少对象,代码如下,求高手指点
<UserControl x:Class="SilverlightApplication1.MainPage"
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"
d:DesignHeight="350" d:DesignWidth="500">
<Grid x:Name="LayoutRoot" Background="White">
<Ellipse x:Name="MyElipse" Fill="White" Stroke="Black" Height="85" Margin="51,31,59,0" VerticalAlignment="Top" MouseEnter="myElipse_MouseEnter" MouseLeave="myElipse_MouseLeave"/>
<Slider x:Name="MySlider" Height="5" Margin="41,246,47,0" VerticalAlignment="Top" Maximum="200" Minimum="10" Value="0" ValueChanged="MySlider_ValueChanged"/>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
MySlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(MySlider_ValueChanged);
}
void MySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
MyElipse.Width = MySlider.Value;
MyElipse.Height = MySlider.Value;
}
private void myElipse_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
// TODO: Add event handler implementation here.
MyElipse.Fill = new SolidColorBrush(Colors.Blue);
}
private void myElipse_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
// TODO: Add event handler implementation here.
MyElipse.Fill = new SolidColorBrush(Colors.Red);
}
}
}
[解决办法]
这样很难判断问题在哪里。能把错误信息贴上来看看么?
[解决办法]
void MySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { if (MyElipse != null) { MyElipse.Width = MySlider.Value; MyElipse.Height = MySlider.Value; } }
[解决办法]
你的应用初始化时就失败了,将MainPage中的 MySlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(MySlider_ValueChanged);
注释掉,然后看看是否有错误?如果没有错误,说明 MySlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(MySlider_ValueChanged);
有问题。
[解决办法]
我感觉是你的环境问题,你试着重新建一个SL工程 什么也不写 看看能不能运行