0
votes

The problem:

This will not work in Code behind for below Button UI :

string strButtonText = btnConfirm.Content.ToString();

your help is greatly appreciated. TIA


<Button x:Name="btnConfirm" Background="Crimson" Foreground="White" FontSize="21" HorizontalAlignment="Left" Margin="662,640,0,0" VerticalAlignment="Top" Height="93" Width="166" Click="btnConfirm_Click">

  <TextBlock Text="Begin" TextWrapping="Wrap" Width="138" Height="61" />

</Button>

The code only work for normal buttun UI:

<Button x:Name="btnConfirm" content="Begin" Background="Crimson" Foreground="White" FontSize="21" HorizontalAlignment="Left" Margin="662,640,0,0" VerticalAlignment="Top" Height="93" Width="166" Click="btnConfirm_Click />


Update : 

How to you set the text back to the button UI in code ??


if (strButtonText.Contains("Begin Date") || strButtonText.Contains("Begin"))
 {

       ???
     btnConfirm.Content = "End Date";


   }
   else
   {
         ??
        btnConfirm.Content = "Begin";
  }


2

2 Answers

0
votes

Okay the same would work for win rt as well.

Try getting it like this:

 //Getting
 string s = (btnConfirm.Content as Windows.UI.Xaml.Controls.TextBlock).Text;
 //Setting
 (btnConfirm.Content as as Windows.UI.Xaml.Controls.TextBlock).Text = "Hello";  
0
votes

Try this

  <Button  x:Name="btnConfirm" Tag="{Binding ElementName=content,Path=Text}" Background="Crimson" Foreground="White" FontSize="21" HorizontalAlignment="Left" Margin="662,640,0,0" VerticalAlignment="Top" Height="93" Width="166" Click="btnConfirm_Click">            
      <TextBlock x:Name="content" Text="begin" TextWrapping="Wrap" Width="138" Height="61" />            
  </Button>

and on click event write

  private void btnConfirm_Click(object sender, RoutedEventArgs e)
    {
        string strButtonText = btnConfirm.Tag.ToString();
    }