![](/img/trans.png)
[英]WPF C# TextBlock. How to format textblock text programatically to format foreground color of certain words that are color names
[英]How to set a text in TextBlock.
如何使用C#在文本塊定義的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;
}
我只是不知道發生了什么。 我只是重新啟動了整個機器,錯誤消失了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.