IT 专业人士的资源 > 论坛主页 > Web 技术 论坛 > Silverlight 技术 > ToolTipService.SetToolTip的报错问题?
提出问题提出问题
 

已答复ToolTipService.SetToolTip的报错问题?

  • 2009年10月27日 15:00worldman 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    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修改错误原代码
    •  

答案

  • 2009年10月29日 8:54Allen Chen - MSFTMSFT, Moderator用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    你好,

    我在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
    •  

全部回复