我想创建一个TextBlock
(或其他一些文本,其中仅显示文本)是垂直的(-90变换角度),但我希望该元素填充它所包含的垂直空间,但是具有定义的水平量(我使用垂直和水平术语而不是高度和宽度,因为当我有TextBlock
go垂直时它被交换),并且它与容器的左侧对齐.
我相信我理解如何TextBlock
使用RenderTransform
或使用LayoutTransform
.然而,无论何时我改变容器的垂直方面,TextBlock
水平方面而不是垂直方向的增加,我似乎无法使"对接"正常工作.
这是我有的:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="AttendanceTracker.StudentView"
x:Name="UserControl" Height="172.666" Width="417.333">
<StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
<Border BorderBrush="Black" BorderThickness="1" RenderTransformOrigin="0.5,0.5" Background="#52FFFFFF" Width="139.667">
<TextBlock Text="My Title" TextWrapping="Wrap" FontSize="18.667" TextAlignment="Center" Foreground="White" Margin="-58.509,68.068,49.158,70.734" Background="Black" RenderTransformOrigin="0.5,0.5" Width="147.017" d:LayoutOverrides="Height">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Border>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
更改UserControl的高度,您会注意到TextBlock
水平方面的增加而不是所需的垂直方面.
有什么方法可以让我只能在文本块上显示一个Bound字符串的第一个字符..?
例如;如果我绑定'男',我的文本块应该只显示'M'.....
我想在Silverlight应用程序中显示文本,以便用户可以将其复制并粘贴到其他位置(就像用于在HTML网站上进行操作一样).
如果我使用TextBlock,则用户无法复制和粘贴.
因此我使用TextBox,但它有一个默认边框.我可以这样删除边框BorderThickness="0"
:
<TextBox
Grid.Column="1"
BorderThickness="0"
Text="{Binding ViewModelBindingStringsBlockHelp}"/>
Run Code Online (Sandbox Code Playgroud)
这很棒:
替代文字http://www.deviantsart.com/upload/45p34i.png
但是,当用户将鼠标悬停在文本框上以选择文本时,会出现另一个边框:
替代文字http://www.deviantsart.com/upload/1k7m44p.png
我找到了用于删除此边框的声称解决方案,但它们令人难以置信地似乎需要XAML 页面.
我正在寻找一个像这样的简单解决方案:
HoverBorderThickness="0"
Run Code Online (Sandbox Code Playgroud)
在Silverlight TextBox上隐藏悬停边框的简单方法是什么?
我有以下代码
txtBlock1.Inlines.Add("This is first paragraph \n This is second paragraph");
Run Code Online (Sandbox Code Playgroud)
然后TextBlock将显示:
This is first paragraph
This is second paragraph
Run Code Online (Sandbox Code Playgroud)
但是,如果我有以下(我虽然相同);
txtBlock1.Inlines.Add("This is first paragraph");
txtBlock1.Inlines.Add("\n");
txtBlock1.Inlines.Add("This is second paragraph");
Run Code Online (Sandbox Code Playgroud)
TextBlock显示:
This is first paragraph // but second paragraph missing
Run Code Online (Sandbox Code Playgroud)
如果我将换行分开,则换行后的其余文本不会显示.为什么?
我必须使用run:
Run run1 = new Run();
run1.Text = "First Paragraph";
run1.Text += "\n";
run1.Text += "Second Paragraph";
txtBlock1.Inlines.Add(run1);
Run Code Online (Sandbox Code Playgroud)
然后它正确地产生结果.为什么我无法添加内联文本Textblock
并要求我使用Run
?
有一些资源标记( 类似于 \r\n)
<Application.Resources>
<system:String x:Key="key1">Line1
Line2</system:String>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
对于主窗口:
<Grid>
<TextBlock Text="{DynamicResource key1}"/>
<Grid>
Run Code Online (Sandbox Code Playgroud)
但结果只有一行:“Line1 Line2”。怎么了?
我有一个TextBlock
地方,其Text
财产与另一个属于一个价值的财产绑定:
<TextBlock Text="{Binding Path=Count}" FontWeight="Bold" />
Run Code Online (Sandbox Code Playgroud)
因此,如果(例如)Count
是4
的,我将在我的TextBlock数见4.
现在,如果我想在数字4之前和之后添加一些文本,我必须做什么(例如我想在方括号[4]中看到这个数字)?
谢谢.
我有这样的xaml代码
<Grid>
<... some grid row and column definitions .../>
<ScrollViewer Grid.Column="1" VerticalScrollBarVisibility="Auto">
<TextBlock "some attribute" />
</ScrollViewer>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我不知道如何配合Textblock
与Scrollviewer
在C#
.我想Textblock
用Scrollviewer
.如果您有其他想法,请告诉我.
非常感谢您的帮助.:d
我正在更新一些现有的 WPF 代码,我的应用程序有许多这样定义的文本块:
<TextBlock x:Name="textBlockPropertyA"><Run Text="{Binding PropertyA}"/></TextBlock>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,“PropertyA”是我的业务类对象的一个属性,定义如下:
public class MyBusinessObject : INotifyPropertyChanged
{
private void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
{
PropertyChanged(this, e);
}
}
private string _propertyA;
public string PropertyA
{
get { return _propertyA; }
set
{
if (_propertyA == value)
{
return;
}
_propertyA = value;
OnPropertyChanged(new PropertyChangedEventArgs("PropertyA"));
}
}
// my business object also contains another object like this
public SomeOtherObject ObjectA = new SomeOtherObject();
public MyBusinessObject()
{
// constructor
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个 …
我在下面有以下ListBox.我不确定如何在选择项目时更改所选项目的文本块文本的前景,然后在取消选择项目时更改为原始前景色(最有可能发生在之后选择ListBox中的其他项目时)?
<ListBox Name="ListBox" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}"
toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel ItemWidth="159" ItemHeight="Auto" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" >
<Image Source="{Binding Thumbnail}" Width="155" Height="155" />
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeNormal}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud) 我想在UWP中自动突出显示网址,电子邮件和电话号码.它可能在Android中,但似乎微软已经忘记了这个功能.在我的用例中,我从Web服务获取文本,因此我不知道文本格式是Web平台上的用户文本输入.
textblock ×10
wpf ×7
xaml ×5
c# ×4
binding ×2
data-binding ×1
listbox ×1
newline ×1
scrollviewer ×1
silverlight ×1
text ×1
textbox ×1
transform ×1
uwp ×1