WPF Textblock, salto de línea en el atributo de texto
¿Hay una manera de hacer que \n
haga un salto de línea en un TextBlock
?
<TextBlock Text="line1\nLine2" />
¿O hay una mejor manera de forzar un salto de línea intermedia, dentro del atributo Text
?
<LineBreak />
Esto no funciona para mí, necesita ser el valor del atributo Text
, porque la cadena de texto se establece desde una fuente externa.
Estoy familiarizado con LineBreak
pero no es la respuesta que estoy buscando.
12 answers
Sé que esto está volviendo a corregir una vieja pregunta, pero yo tenía el mismo problema. La solución para mí fue usar fuentes de línea codificadas HTML (&#10;
).
Line1&#10;Line2
Parece
Line1
Line2
Para obtener más de los caracteres codificados en HTML, consulte w3schools
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-16 14:38:08
Prueba esto:
<TextBlock>
line1
<LineBreak />
line2
</TextBlock>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-15 22:01:36
La forma más fácil es
<TextBlock> blabla <LineBreak /> coucou <LineBreak /> coucou 2 </TextBlock>
Así que simplemente escribes código XAML, y el <LineBreak />
tiene exactamente el mismo significado que el
en HTML o el "\n" en C#.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-24 05:06:31
<LineBreak/>
Http://www.longhorncorner.com/UploadFile/mahesh/XamlLineBreak06092005152257PM/XamlLineBreak.aspx
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-05-07 22:23:40
¿Qué tal si dividimos la línea en dos etiquetas?
<StackPanel>
<TextBlock Text="Line1" />
<TextBlock Text="Line2" />
</StackPanel>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-05-08 00:13:23
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-29 22:12:59
La forma correcta de usarlo puede ser la siguiente:
<TextBlock>
<Span>text1</Span>
<LineBreak/>
<Span>text2</Span>
</TextBlock>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-19 07:02:35
<HyperlinkButton
Content="Apply and restart this pplication! Note that modifying these settings requires the application to be restarted." />
CRLF simple way = !
!
- Trabaja en todos los controles wpf, xaml, silverlight como TextBlock, HyperlinkText y más
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-31 13:12:10
Simplemente use el control AccessText. puede usarlo como una etiqueta y tiene la propiedad TextWrapping="WrapWithOverflow"
Eg.
El mío es así y funciona bien. Además, no tiene ningún problema en cambiar el texto dinámicamente.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-04 12:58:53
Si está vinculando el Texto de TextBlock, ninguna de las otras respuestas funciona. Simplemente agregue '\n ' al texto de enlace donde desea romper.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-10 20:43:20
Llego tarde a la fiesta pero .. esto es más o menos cómo lo hice, (tenga en cuenta que mis ItemSources son cadenas simples , no formateadas, y no necesitaba 'ConvertBack' nada)
public class SpaceToLineBreakConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (!String.IsNullOrEmpty(value as string))
? new Regex(@"\s").Replace(value as string, "\n")
: value;
}
public object ConvertBack(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-26 06:46:44
Estaba teniendo un problema similar y quería enlazar una cadena de marcado xaml a un TextBlock. Esencialmente almacenando el marcado declarativo dentro de un TextBlock en una cadena para su uso posterior.
Así es como lo hice: subclasé el TextBlock para hacer que la InlineCollection sea enlazable y escribí un Convertidor entre la cadena y una InlineCollection(o en realidad una lista genérica de Inlines.)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:26:23