ToolTipService.SetToolTip的报错问题?
cs
private void Button_Click(object sender, RoutedEventArgs e)
{
if (this.txttag.Visibility == Visibility.Collapsed && isCloseed)
{
this.txttag.Visibility = Visibility.Visible;
this.isCloseed = true;
this.txttag.Focus();
}
else
this.txttag.Visibility = Visibility.Collapsed;
}private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (this.Tag.ToString() == "")
{
//ToolTip tt = new ToolTip();
//tt.IsOpen = true;
//tt.Content = "参数不能为空";
ToolTipService.SetToolTip(btncontent, "参数不能为空"); 在这个地方报错。。。。。不知道什么原因
报 未将对象引用设置到对象的实例
//this.btncontent.Dispatcher.BeginInvoke(() => ToolTipService.SetToolTip(this.btncontent, "参数不能为空"));
//MessageBox.Show("参数不能为空");
//this.Button_Click(null, null);
//return;
}
}bool isCloseed = true;
private void txttag_LostFocus(object sender, RoutedEventArgs e)
{
isCloseed = false;
this.Tag = this.txttag.Text;
this.txttag.Visibility = Visibility.Collapsed;
//MessageBox.Show(this.Tag.ToString());
}xaml
<UserControl x:Class="xbrother.silverlight.Controls.ControlView.ButtonView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="100" Height="30" Tag="">
<Button Click="Button_Click_1" x:Name="btncontent">
<Grid Width="100">
<Grid x:Name="LayoutRoot" Margin="0 0 30 0">
<TextBlock Text="123666655554" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBox x:Name="txttag" LostFocus="txttag_LostFocus" Visibility="Collapsed"></TextBox>
</Grid>
<Button Margin="0 0 10 0" HorizontalAlignment="Right" Click="Button_Click">
<Button.Template>
<ControlTemplate>
<Image Source="/Login;component/image/HighlightHS.png" VerticalAlignment="Center" HorizontalAlignment="Right" Width="16" Height="16"></Image>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Button>
</UserControl>- 已编辑worldman 2009年10月28日 2:33修改错误原代码
答案
- 你好,
我在Silverlight 3 环境下试验过了,并没有报错啊.你升级到Silverlight 3看看呢?
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.- 已标记为答案worldman 2009年10月29日 10:38
全部回复
- ToolTipService.SetToolTip(btnContent, "2222");
原代码已修改。。。环境重现
ToolTipService.SetToolTip(btncontent, "参数不能为空"); 在这个地方报错。。。。。不知道什么原因
就在这个地方。。- 你的代码没问题! 我用2.0测试 不知道你的是多少
- 我也是2.0的环境下的...奇怪勒.
是Button_Click_1这个事件触发导致触发了Button_Click...
今天调试发现的.但到底出错在什么地方.还有待分析... - 你好,
可以提供一下重现问题的项目吗? 请将项目上传到http://skydrive.live.com/ 然后贴一下连接.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us. - http://cid-37434adbab92fbe7.skydrive.live.com/self.aspx/.Public/SilverlightApplication1.rar
感谢..我发现是在点下去的时候没事。。鼠标移动一下就出问题了。。 - 你好,
我在Silverlight 3 环境下试验过了,并没有报错啊.你升级到Silverlight 3看看呢?
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.- 已标记为答案worldman 2009年10月29日 10:38
感谢楼主帮我验证。。谢谢。!
我是在2.0环境下弄出这个问题来着。。
由于一直在用2.0暂时不想升级到3.0 。
其实也不是什么大问题...总有办法解决... 谢谢楼上了。

