如何为TextBlock中的文本指定垂直居中对齐?我找到了TextAlignment属性,但它用于水平文本对齐.如何进行垂直文本对齐?
如果我将一段文本分配给a的Content属性,则由at渲染时生成ContentPresenter一个TextBlock控件ContentPresenter以包含该文本.
如果我创建一个适用于TextBlock属性并将其分配给它的样式,则该样式ContentPresenter似乎不适用于隐式生成的TextBlocks.
<Style x:Key="SampleStyle">
<Setter Property="TextBlock.TextWrapping" Value="Wrap"/>
</Style>
<ContentPresenter Content="This is a Test piece of text." Style="{StaticResource SampleStyle}"/>
Run Code Online (Sandbox Code Playgroud)
有没有办法成功地将这种风格应用于自动生成TextBlocks将其应用于所有TextBlocks(例如声明样式为TargetType="TextBlock"no Key)?
我有一个贴在某物上的标签.如果字符串太长,我希望标签在宽度和高度上扩展,以便它适合屏幕.
我有这个:
<StackPanel Orientation="Horizontal" Margin="0,0,0,200" Height="50" Width="900">
<Label HorizontalContentAlignment="Left" VerticalAlignment="Center" Padding="5" FontSize="24" Content="Instruction: " Width="290" />
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="25" Text="{Binding InstructionLabel}" Width="auto" Height="auto" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
请注意,我尝试使用TextBlock而不是Label.这不是很难,所以我试过:
<Label HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="25" Width="auto" Height="auto">
<AccessText TextWrapping="WrapWithOverflow" Text="{Binding InstructionLabel}"/>
</Label>
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.
View现在是这样的: