showing dynamic text in silverlight

2019-03-04 16:26发布

I have a button which shows "click me!" on it. I want to see that when I click on the button, it shows "Do not click on me!"

I have a button in my Search.xaml file like below and it always show "click me!".

<Button x:Name="buttonname" Canvas.Top="60" Canvas.Left="30" Click="btnTest_Click" Content="click me!"></Button>

Also my Search.xaml.cs looks like below:

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;
using System.Windows.Media.Imaging;

namespace TMTemplate
{
    public partial class Search : Page
    {
        public Search() { 
            InitializeComponent();
        }
        private void btnTest_Click(object sender, RoutedEventArgs e)
        {
            this.Content = "Do not click on me!";
        }   
    }
}

This is not working and I have spent lots of time to figure this out, Would you please let me know how I can get it working...

Thank you so much.

1条回答
做自己的国王
2楼-- · 2019-03-04 16:50
this.Content = "Do not click on me!";

should be

buttonname.Content = "Do not click on me!";
查看更多
登录 后发表回答