Simple Button.Text not changing properly

Hi all,
The WPF learning curve is steep.
I have pulled my hair over this simple Button.Text change and I can't get it to work.
In WinForms this works:
Public Class Form1
Private Sub BTN_1_Click(sender As Object, e As EventArgs) Handles BTN_1.Click
BTN_1.Text = "CLICKED BUTTON 1"
BTN_2.Text = "CHANGED BY BUTTON 1"
End Sub
Private Sub BTN_2_Click(sender As Object, e As EventArgs) Handles BTN_2.Click
BTN_2.Text = "CLICKED BUTTON 2"
BTN_1.Text = "CHANGED BY BUTTON 2"
End Sub
End Class
I want to do the same thing in WPF
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Grid.Row="0">
<Button Name="BTN_1" Click="CLICK_BTN_1">
<StackPanel>
<TextBlock Name="CLICK_BTN_1_LABEL_1" Text="Button 1 text" VerticalAlignment="Top" Foreground="#BF000000" >
</TextBlock>
<TextBlock Name="CLICK_BTN_1_LABEL_2" VerticalAlignment="Top" Foreground="#BF000000">
<Run FontSize="25">Button 1</Run>
<Run FontSize="12">Label 2</Run>
</TextBlock>
</StackPanel>
</Button>
</Grid>
<Grid Grid.Column="1" Grid.Row="0">
<Button Name="BTN_2" Click="CLICK_BTN_1">
<StackPanel>
<TextBlock Name="CLICK_BTN_2_LABEL_1" Text="Button 2 text" VerticalAlignment="Top" Foreground="#BF000000">
</TextBlock>
<TextBlock Name="CLICK_BTN_2_LABEL_2" VerticalAlignment="Top" Foreground="#BF000000">
<Run FontSize="25">Button 2</Run>
<Run FontSize="12">Label 2</Run>
</TextBlock>
</StackPanel>
</Button>
</Grid>
</Grid>
</Window>
Class MainWindow
Private Sub CLICK_BTN_1(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles BTN_1.Click
' CHANGE LABEL 1 ON BUTTON 1
CLICK_BTN_1_LABEL_1.Text = "CLICKED BUTTON 1"
' CHANGE LABEL 1 ON BUTTON 2
CLICK_BTN_2_LABEL_1.Text = "CHANGED BY BUTTON 1"
End Sub
Private Sub CLICK_BTN_2(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles BTN_2.Click
' CHANGE LABEL 1 ON BUTTON 1
CLICK_BTN_1_LABEL_1.Text = "CHANGED BY BUTTON 2"
' CHANGE LABEL 1 ON BUTTON 2
CLICK_BTN_2_LABEL_1.Text = "CLICKED BUTTON 2"
End Sub
End Class
This used to be so simple with WinForms, what am I doing wrong here?
New to WPF

Yeah, I saw that as well but now I am stuck again:
Same project but I have put the buttons in a usercontrol
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Component_Changes"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Grid.Row="0">
<Viewbox Stretch="Fill">
<ContentControl Name="UC_BTN1">
<ContentControl.Content>
<local:btn1 Margin="20"/>
</ContentControl.Content>
</ContentControl>
</Viewbox>
</Grid>
<Grid Grid.Column="1" Grid.Row="0">
<Viewbox Stretch="Fill">
<ContentControl Name="UC_BTN2">
<ContentControl.Content>
<local:btn2 Margin="20"/>
</ContentControl.Content>
</ContentControl>
</Viewbox>
</Grid>
</Grid>
</Window>
btn1.xaml
<UserControl x:Class="btn1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Name="BTN_1" Click="CLICK_BTN_1">
<StackPanel>
<TextBlock Name="CLICK_BTN_1_LABEL_1" Text="Button 1 text" VerticalAlignment="Top" Foreground="#BF000000" >
</TextBlock>
<TextBlock Name="CLICK_BTN_1_LABEL_2" VerticalAlignment="Top" Foreground="#BF000000">
<Run FontSize="25">Button 1</Run>
<Run FontSize="12">Label 2</Run>
</TextBlock>
</StackPanel>
</Button>
</Grid>
</UserControl>
btn1.xaml.vb
Public Class btn1
Dim CL_BTN2 As btn2
Private Sub CLICK_BTN_1(sender As Object, e As RoutedEventArgs) Handles BTN_1.Click
' CHANGE LABEL 1 ON BUTTON 1
CLICK_BTN_1_LABEL_1.Text = "CLICKED BUTTON 1"
' CHANGE LABEL 1 ON BUTTON 2
CL_BTN2.CLICK_BTN_2_LABEL_1.Text = "CHANGED BY BUTTON 1"
End Sub
End Class
btn2.xaml
<UserControl x:Class="btn2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Name="BTN_2" Click="CLICK_BTN_2">
<StackPanel>
<TextBlock Name="CLICK_BTN_2_LABEL_1" Text="Button 2 text" VerticalAlignment="Top" Foreground="#BF000000">
</TextBlock>
<TextBlock Name="CLICK_BTN_2_LABEL_2" VerticalAlignment="Top" Foreground="#BF000000">
<Run FontSize="25">Button 2</Run>
<Run FontSize="12">Label 2</Run>
</TextBlock>
</StackPanel>
</Button>
</Grid>
</UserControl>
btn2.xaml.vb
Public Class btn2
Dim CL_BTN1 As btn1
Private Sub CLICK_BTN_2(sender As Object, e As RoutedEventArgs) Handles BTN_2.Click
' CHANGE LABEL 1 ON BUTTON 1
CL_BTN1.CLICK_BTN_1_LABEL_1.Text = "CHANGED BY BUTTON 2"
' CHANGE LABEL 1 ON BUTTON 2
CLICK_BTN_2_LABEL_1.Text = "CLICKED BUTTON 2"
End Sub
End Class
No warnings in the code but the error is: 'Object reference not set to an instance of an object' and I thought I did, obviously not in the right way.
New to WPF

Similar Messages

  • Centre button is not working properly in my iphone . . what can i do for that ?

    centre button is not working properly in my iphone . . what can i do for that ?

    Get it serviced.

  • Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Thanks for that information!
    I'm sure I will be calling AppleCare, but the problem is, they charge for the phone calls don't they? Because I don't have money to be spending to be on the phone with a support service.
    In other things, it seemed like the only time my MacBook was working was when I had Snow Leopard without the 10.6.8 update download that was supposed to be done to prepare for OS X Lion.
    When I look at the information of my HD it says that I have 10.6.8 but that was the install that it claimed to have failed and caused me to restart resulting in all of the repeated problems.
    Also, because my computer is currently down, and I've lost all files how would that effect the use of my iPhone? Because if it doesn't get fixed by the time OS 5 is released, how would I be able to upgrade?!

  • ICal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed on alert.

    iCal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed.

    Calendar (not called iCal anymore) does not include that capability any longer, apparently.  What you have to do now is go to Automator and create a Calendar Alert action.  You can add a Run AppleScript object to the action and paste in your script there, then when you save it, it will become available as a choice in the alert menu in Calendar.

  • Simple pass is not woking properly

    simple pass is not woking properly I am unable to sign into mails. when i click the web card a box appiars and it says set ur default browser my default browser is IE9   Ineed updates to solve this problem

    Thank you for visiting the HP Support Forums. Just a reminder that this is a peer-to-peer community of HP customers, and not a venue to contact HP directly. Most of the users here are consumers like yourself who are offering solutions because they like to help others, and any HP employees you see are here on their own capacity and not representing the company.
    If you have additional or direct feedback for HP about their products or services, or questions about repair, you can use the link below for contact information.
    http://www8.hp.com/us/en/contact-hp/ww-contact-us.html
    If you have other questions and concerns about using the forum, please feel free to send me a private message.
    OrnahP
    HP Support Forums Moderator
     Clicking the "Kudos Star" to the left is a great way to say thanks!
     When your problem has been solved, accept the solution by clicking "Accept as Solution" to help other members in the future!
    Rules of Participation

  • I phone 3gs home button is not working properly

    Hi Folks..
    From the last few days my I phone 3GS is giving me a hard time.. Its HOME BUTTON is not working properly. Have to press it 2-3 times and have to press it hard to make it work. I am now running 5.1 iOS, it had the same problem with 5.0.1 iOS too. Can you suggest me what to do??? Do i need to take it to the service centre????

    I've just noticed this too, after updating my 3GS to iOS 5.1.  It seems to be happening off and on, but it is more of a problem when the phone has set locked and idle for a few minutes.
    I usually wake it from sleep with the power button, unlock it, and wait for the ability to use the home button.
    It might be worth it to take it to the Genius Bar or at least try to live chat with Apple Customer Service.
    I feel your pain.

  • After I updated to iOS 7.0.2 my lock button is not working properly

    After I updated to iOS 7.0.2 my lock button is not working properly I push the button many times and after many failed attempts it locks and sometimes not. I had to use the accesibility tool to lock it manually from the screen, this is really annoying.

    I guess it is.
    Do you have a question, or are you just sharing your experience with us?

  • Cancel button does not work properly in ProgressMonitor

    The cancel button does not work properly in my ProgressMonitor.
    Only the keyboard Enter key is accepted but no mouse click.
    Everything else works fine.
    What could be wrong????
    Thank you!

    Yes, there is a monitor.isCanceled() and it works if the enter key is pressed. However, a mouse click on the cancel button does not work!!!
    Please help.
    m_btnSave.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent arg0) {
              final int maximum = getMyModel().getList(MerchantHierPropagateMgrDataInterface.ATT_MAN_RESULT).size();
              class TimerListener implements ActionListener {
                   public void actionPerformed(ActionEvent evt) {
                        System.out.println("*************isCanceled = "+ m_monitor.isCanceled());
                        if (m_monitor.isCanceled() || getMyModel().isDone()) {
                             m_timer.stop();
                             m_monitor.close();
                             if (getMyModel().isDone()) {
                                  m_ok = true;
                                  close();
                             else {
                                  m_worker.interrupt();
                                  try {
                                       m_pm.rollback();
                                  } catch (SQLException e) {
                                       BPrompter.showException(e);
                                       Log.printOutAlways(e);
                        else {
                             int progress = getMyModel().getProgess();
                             int prozent = maximum == 0 ? 0 : 100 * progress / maximum ;
                             m_monitor.setProgress(progress);
                             m_monitor.setNote("Fertigstellung: (" + prozent + "%) " + progress + " von " + maximum);
              if (getModel().getList(MerchantHierPropagateMgrDataInterface.ATT_MAN_RESULT).size() > 100) {
                   if (BPrompter.showConfirmDialog("Diese Funktion kann mehrere Minuten dauern.", "Hinweis") != JOptionPane.OK_OPTION) {
                        return;
              m_monitor = new ProgressMonitor(FrameApplication.getInstance(), "Fortschritt der Weitergabe",
                        "Initialisierung", 1, maximum);
              m_monitor.setMillisToDecideToPopup(0);
              m_monitor.setMillisToPopup(0);
              m_timer = new Timer(500, new TimerListener());
              m_timer.start();
              m_worker = new SwingWorker() {
                   public Object construct() {
                        try {
                             getMyModel().propagateToMerchantsAndTerminals(m_pm,     m_mutationInZukunftZuErledigenBisDate);
                        } catch (PersistenceException e) {
                             Log.printOutAlways(e);
                             return e;
                        return Boolean.TRUE;
                   } // constuct()
              }; // SwingWorker
              m_worker.start();
    });

  • HT1349 my home button will not work properly... I have to hold it down several times for it to go to the home screen

    my home button will not work properly... I have to hold it down several times for it to go to the home screen

    I would try a restore just to see if it could be something software related, but if that doesn't work I would recommend taking to an Apple Store to see if it is a serious hardware issue and if it is, assuming you're in warranty, then they would be able to replace your phone.

  • Why is button value not changing?

    I have a fairly complex form with several input text fields and buttons that have their values changed during operation.
    The components are created from a session bean and are updated by two different mechanisms.
    The input text fields are updated by user input.
    The button acts as a toggle. When the user pushed the button, a javascript function checks the value of the button.
    The button contains a single character, either a "X" or "O".
    When the button is pushed, the javascript checks the value and changes it to the other.
    Visually, this all works fine. Both the text fields and buttons behave as expected.
    Here is the problem.
    When the user pushes the "Apply" button, a session bean looks for the text fields and buttons using 'findComponent' for a specified ID.
    They attempt to fetch the values of the components and update an internal array of values.
    The input text component works fine.
    User changes value, it is identified correctly, and the new value is detected on the component.
    The commandButton component does not work as expected.
    Visually, the component value changes properly.
    When I use findComponent() and getValue(),. I get the original value.
    I have verified that the component ID is correct - I print it with an Alert() method in the javascript and check it with the debugger before the findComponent() method.
    But, what is returned from getValue() of the found component is the original value, not the value that is visually displayed on the form.
    Can anyone explain why this happens and what I can do to get the correct visually displayed value from the button component?
    Thanks.

    <h:inputHidden value="#{myBean.myProp}" />Although this is annoying on the client side because the client id is rendered as the name.
    Alternatively:
    <input type="hidden" name="myProp" value="#{myBean.myProp}" />along with the following bean config:
        <managed-bean>
           <managed-bean-name>myBean</managed-bean-name>
           <managed-bean-class>MyBeanClass</managed-bean-class>
           <managed-bean-scope>request</managed-bean-scope>
           <managed-property>
                <property-name>myProp</property-name>
                <property-class>java.lang.String</property-class>
                <value>#{param.myProp}</value>
           </managed-property>
        </managed-bean>

  • Maximize/minimize and close buttons do not work properly

    Suddenly the buttons at the top right are not working properly. There is no change in appearance when hovering the mouse over it. This does not occur immediately after I open firefox but shortly afterwards. I noticed by accident that if I open the options box and close it again these buttons will work for a while. It also applies to dialogue boxes that open up as well. I did not add any plugins, but I do believe there was a recent update for firefox installed. Thanks

    Thanks, however I am on release 18.0. I am not quite sure yet but I think the problem may have solved itself. Since I first posted if happened a few times but nothing over the past couple of hours so perhaps the issue resolved itself. I'll repost if it does. Thanks again

  • TestStand Simple OI does not close properly

    Hi there.
    We have build a test system that is running TestStand 4.2 and the code modules are created with LabVIEW 9.0. The SW is running on a PC with Windows XP.
    We are currently using TestStand Simple Operator Interface (LabVIEW version) to run the tests, and it is with the Operator Interface that we are having a problem.
    If we use the TestExec.exe file that came with the TestStand installation everything works fine. But we need to make some modifications to OI and if we open the project file and recompile the OI, then the OI will not close properly. It seems to shutdown the testengine and stop execution of the VI, but the window does not disappear until we move the mouse.
    When I open the project file LabVIEW informs me that the project was last saved in version 7.1.1 and we are now running 9.0.
    Can anyone tell me what is holding the window on the screen until there is activity on the mouse?
    Solved!
    Go to Solution.

    I was looking through TestStand 4.2 known issues, and I found this:
    ID# 148697
    LabVIEW User Interface might hang when using LabVIEW events
    A LabVIEW User Interface that registers ActiveX callbacks and uses an event structure might hang when the user interacts with a LabVIEW control or indicator. The hang is rare, but when it occurs, TestStand User Interface (UI) Controls remain responsive, but all LabVIEW User Interface elements appear frozen.
    Workaround: Activate another application and reactive the LabVIEW User Interface.
    Not exactly the same as I am experiencing but sounds similar - Does anyone know more about this issue?

  • Simple button script not working

    I am using AS2 and need help figuring out why this simple button script is not working:
    stop();
    buttonWS1.onRelease = function(){
                        gotoAndStop("Stage1and2_Boss",4);
    buttonWS2.onRelease = function(){
                        nextFrame();
    //end
    My buttons are the square letter-puzzles below. They are images that I converted to "symbols" (specifically, buttons). I put their names as above (buttonWS1, buttonWS2, etc.) in the "instance names" boxes.
    I have no idea what is going on. Please help!

    Hi -
    1. Yes, buttonWS2 is the instance name
    2. The only code attached to it is the code I pasted above.
    3. onRelease does not execute because my trace statement does not appear in the output
    Here is the modified code for buttonWS2:
    buttonWS2.onRelease = function(){
                        trace("clicked!");
                        nextFrame();
    Question: It shouldn't matter if I have commented-out code within that set of codes should it?:
    buttonWS2.onRelease = function(){
              //if (puzzleschosenarray[0] == 2 || puzzleschosenarray[1] == 2) {
              // cannot be chosen -- make button non-functional
              //else{
                        //puzzleschosenarray[roundnumber-1] = 2;
                        trace("clicked!");
                        nextFrame();

  • Home/sleep button is not working properly. why?

    i just bought i new ipod on ebay. But home and sleep button on my ipod touch 4th generation is not working properly after long sleep time. but it works properly when its plugged-in for charging..why? how can i solve it?

    Hi,
    Try resetting your iPod:  http://support.apple.com/kb/HT1430. 
    Hope this helps! 
    ---likeabird---

  • Non-button text not showing up in menu

    Is it normal for text in a Blu-ray menu that is not a button to not show up in the menu once it is on a disc or disc image? This is the last issue I am having.
    I have some text on a menu that is just text. I have had plain text in the past work perfectly, but this time around Encore isn't rendering it. In the past though, my motion menu footage was in compliant m4v format, and this time it's mp4 so that Encore would transcode it. Using m4v was causing red frames to show up in the footage.
    Is there a way for me to fix this easily, either in Encore of Photoshop?

    I feel really slow...
    The only background in a multipage menu is the background in page 0.
    When you add anything to the page 1 or 2 groups, it can only be a button.
    So yes, the workaround to getting text that only shows on a single page is to put it in a button.
    You told us everything we needed in the original post, except, of course, that it was a multipage - but the symptom made that an easy guess. Sorry a little slow on getting there!

Maybe you are looking for

  • TABLE for finding PTAX CITY

    Hi Experts,     I need a help .    In HR module .     Can u provide me the table  where i can take the PROFESSIONAL TAX CITY field.??     Is there any infotype for this field.     Kindly Mention the Key fields.    Thanks a lot

  • Verifying DSN reports Datasource not found?

    Hello, thanks for looking.. I have two datasources configured on a production web server (Win IIS, CF8), one that connects to a remote database and the other connects to a local database. A web application I was in the process of migrating to a new s

  • How can i set the different colors for a different group ui elements

    Hi All,               I Created a View Container in that i crated 2 views. In first view i created a group and in second view also i created a group. I want to set The First view group header colour as Golden colour and for second view group heder co

  • Why can't I sign in to the App Store app on my mac?

    Is there anyone who can help me? I have OS 10.7.4 running on a Intel mac tower, I have an Apple account (that works fine for the iTune store, on my iPad), but when I click on the either of the links; Sign In, or Account in the App Store app on my mac

  • How long does it take to transfer data from a PC to a Mac?

    Using Migration Assistant and I am transferring data from PC to IMac. Have no idea how ling this process should take. How long does it take to transfer data from a PC to a Mac?