如何使用c#在textblock中定義xaml中的文本。我正在重定向到一個電話頁面,裏面有一個stackpanel和幾個文本塊。如果我命名一個文本塊,並在c#代碼中調用它,它不起作用。如何在加載頁面時在文本塊中設置字符串...並且文本從前一頁傳遞。基本上文本塊中無法識別...如何使其在C#代碼可見......如何在TextBlock中設置文本。
XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="16,0,12,0">
<StackPanel x:Name="activationPanel" Margin="0,10">
<TextBlock TextWrapping="Wrap" Text="Almost there !" FontFamily="Segoe UI" FontWeight="Light" FontSize="24" Foreground="#FF486070"/>
<TextBlock TextWrapping="Wrap" Text="An activation mail has been sent" FontFamily="Segoe UI" FontWeight="Light" FontSize="24" Foreground="#FF486070" Margin="0,18,0,0"/>
<TextBlock Name="useremail" TextWrapping="Wrap" FontFamily="Segoe UI" FontWeight="SemiBold" FontSize="24" Foreground="#FF486070" Margin="0,10,0,0" LostFocus="useremail_LostFocus"/>
<TextBlock TextWrapping="Wrap" Text="please click on the link to activate your account" FontFamily="Segoe UI" FontWeight="Light" FontSize="24" Foreground="#FF486070" Margin="0,50,78,0"/>
<Button x:Name="btnAcA" Content="ACCOUNT ACTIVATED" Width="335" HorizontalAlignment="Left" Height="42" Padding="12,0,10,0" Background="#FF55D782" BorderBrush="{x:Null}" BorderThickness="0" FontSize="16" FontFamily="Segoe UI" Style="{StaticResource LoginButtonStyle}" Margin="0,90,0,25" Click="btnAcA_Click"/>
<Button x:Name="btnRAM" Content="RESEND ACTIVATION MAIL" Width="335" HorizontalAlignment="Left" Height="42" Padding="12,0,10,0" Background="#FF637A8A" BorderBrush="{x:Null}" BorderThickness="0" FontSize="16" FontFamily="Segoe UI" Style="{StaticResource LoginButtonStyle}" Margin="0,0,0,25"/>
</StackPanel>
</Grid>
C#:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string email=null;
if (this.NavigationContext.QueryString.ContainsKey("email"))
{
email = this.NavigationContext.QueryString["email"];
}
Debug.WriteLine(email);
setTextBoxValue(email);
}
private void setTextBoxValue(string email)
{
//TextBlock useremail = new TextBlock();
useremail.Text = email;
}
是否在代碼隱藏的同一類中使用「useremail」標記(即,它不在嵌套控件/用戶控件中)? – McGarnagle
我試過x:useremail for textblock。對於TextBlock來說非常特別,它在c#代碼中不被識別。對於文本框x:somename運行良好。任何想法,在TextBlock中有什麼特別的? – user88975
你能訪問'btnRAM'嗎?像這樣的'btnRAM.Content = toto'in'setTextBoxValue'? – aloisdg