如何使用c#在textblock定义的xaml中设置文本。我正在重定向到一个电话页面,里面有一个堆叠面板和几个文本块。如果我命名一个文本块并在c#代码中调用它,它就不起作用了。如何在加载页面时在文本块中设置字符串...并从上一页传递文本。基本上文本块无法识别......如何在c#代码中显示它...
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;
}
答案 0 :(得分:1)
我只是不知道发生了什么。我只是重新启动整个机器,错误就消失了。
答案 1 :(得分:0)
查看this问题。根据接受的答案,原因可能是: