none
How to get content of kinect toolkit button in Xaml.cs in WPF RRS feed

  • Question

  • I want to get content of button but error occurred. Error is "{"Object reference not set to an instance of an object."}" Below code will tell you what i am doing.
          <k:KinectTileButton HorizontalAlignment="Left" Content="Right Arm " Margin="20,318,0,0" VerticalAlignment="Top" Height="82" Width="259" Background="CornflowerBlue" Click="KinectTileButton_Click_1" />

            private void KinectTileButton_Click_1(object sender, RoutedEventArgs e)
            {
                string BtnName;
                BtnName = (sender as System.Windows.Controls.Button).Content.ToString();
                Exercise exe = new Exercise(sensorChooser,BtnName);
                exe.Show();
                this.Close();
            }

    Sunday, November 16, 2014 6:05 PM

Answers

  • Cast is incorrect that's why error.....

    Solution

    BtnName = (sender as Microsoft.Kinect.Toolkit.Controls.KinectTileButton).Content.ToString();


    • Edited by DanyalHaider Monday, November 17, 2014 8:35 PM
    • Marked as answer by DanyalHaider Monday, November 17, 2014 8:42 PM
    Monday, November 17, 2014 8:34 PM

All replies

  • You should be checking to ensure the cast is not null before assuming you can pull the Content property from it. KinectTileButton inherits from ButtonBase. If you need it to inherit from something else, since the code is provided, you can modify the controls to suit your requirements.


    Carmine Sirignano - MSFT



    Monday, November 17, 2014 7:44 PM
  • Cast is incorrect that's why error.....

    Solution

    BtnName = (sender as Microsoft.Kinect.Toolkit.Controls.KinectTileButton).Content.ToString();


    • Edited by DanyalHaider Monday, November 17, 2014 8:35 PM
    • Marked as answer by DanyalHaider Monday, November 17, 2014 8:42 PM
    Monday, November 17, 2014 8:34 PM