标签: textblock

如何在文本框中添加超链接和文本

这是我的代码:

<TextBlock TextWrapping="Wrap" TextAlignment="Left">
   <TextBox IsReadOnly="True" BorderThickness="0" TextWrapping="Wrap">    
      Please enter your details for login: questions follow the link 
   </TextBox>
   <Hyperlink NavigateUri="https:" RequestNavigate="Hyperlink_RequestNavigate">
      Reset Password
   </Hyperlink>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

文本框不允许我在文本中设置超链接。我需要将超链接保留在文本框中,这会创建一个新行。但我想要与文本串联的超链接。

我在 TextBlock 中使用 TextBox 的原因是为了使文本可选择。

wpf textbox textblock hyperlink

2
推荐指数
1
解决办法
6270
查看次数

使用静态资源连接文本块中的字符串(无绑定)

我尝试做这样的事情:

<Label Content="{x:Static localization:localization.Offset}" ContentStringFormat="{}{0} A"/>
Run Code Online (Sandbox Code Playgroud)

该行的结果是:“Offset A”

我想用文本块来做到这一点。那可能吗?

string wpf concatenation string-concatenation textblock

2
推荐指数
1
解决办法
1054
查看次数

Viewbox 中的文本块不是多行

我在自动调整文本大小方面遇到了一些麻烦。我在某处读到,如果我想实现这一目标,我需要将我的文本块放在viewbox中。问题是文本不会分成多行。例如,“非常非常长的文本”几乎无法阅读,但“简单文本”看起来就很好。

<Viewbox Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="4" StretchDirection="DownOnly">
     <TextBlock 
         Text="{Binding FieldName}" VerticalAlignment="Center" HorizontalAlignment="Center"
         TextWrapping="Wrap" FontWeight="Bold" FontFamily="Nueva Std" />
</Viewbox>
Run Code Online (Sandbox Code Playgroud)

先感谢您!

c# wpf xaml textblock viewbox

2
推荐指数
1
解决办法
1503
查看次数

如何将数据绑定到Run的内容?

我想构造一个TextBlock由几个Run元素组成,其内容绑定到string变量,但Visual Studio抱怨,说只能绑定到依赖属性,而Run.Text不是.

有什么可以做的吗?

c# wpf binding textblock

1
推荐指数
1
解决办法
112
查看次数

如何将此TextBlock淡入触发器转换为样式

此XAML使文本在显示时淡入.

我想把这个功能放到Style中.

但是,但是我为"TargetName"添加了什么,因为样式不知道哪个元素将使用它?

如何将此淡入效果转换为样式?

<TextBlock Name="Message" Text="This is a test.">
  <TextBlock.Triggers>
    <EventTrigger RoutedEvent="TextBlock.Loaded">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation
            Storyboard.TargetName="Message" 
            Storyboard.TargetProperty="(TextBlock.Opacity)"
            From="0.0" To="1.0" Duration="0:0:3"/>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </TextBlock.Triggers>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

wpf xaml styles textblock

1
推荐指数
1
解决办法
1828
查看次数

wpf在textblock上旋转并转换转换问题

我有一个字符串列表,我绑定到一个项目控件.

字符串显示在我在itemscontrol模板中声明的文本块中.我已经旋转了文本块270以使文本在它的一边 - 我还将文本块的宽度向下翻译,使它们位于页面的顶部.

我的问题是它们现在距离太远,因为它保持原始宽度而不是变换宽度.我能理解它为什么这样做,但我需要把它们叠在一起,没有间隙.

有人能指出我正确的方向吗?

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="354" Width="632"
        DataContext="{Binding RelativeSource={RelativeSource Self}}" >
<Window.Resources>
    <TransformGroup x:Key="Rotate">
        <RotateTransform Angle="270" />
        <TranslateTransform Y="200" />
    </TransformGroup>
</Window.Resources>
<StackPanel Orientation="Vertical">
    <ItemsControl ItemsSource="{Binding MyStrings}" HorizontalAlignment="Left"  >
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderThickness="1" BorderBrush="Black" Width="200" Height="20" RenderTransform="{StaticResource Rotate}" >
                    <TextBlock Text="{Binding }"  >
                    </TextBlock>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

并且背后的代码只是......

使用System.Collections.Generic; 使用System.Windows;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class …
Run Code Online (Sandbox Code Playgroud)

wpf transformation textblock itemscontrol

1
推荐指数
1
解决办法
8496
查看次数

将Textblock文本绑定到2个不同的属性

我有一个绑定的树视图,它显示了treeviewitem的一个属性(即displayname)(它们是一个对象的自定义视图模型).

这是相关的xaml:

<local:ExtendedTreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding SubOrganLocations}">
                        <TextBlock Text="{Binding OrganDisplayName}" >
                        </TextBlock>
                    </HierarchicalDataTemplate>
                </local:ExtendedTreeView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

我想要的是能够在括号中显示显示名称旁边的另一个属性.

所以不是看起来像这样的树视图:

Root
-sub node1
--subsub node1
-sub node2
Run Code Online (Sandbox Code Playgroud)

我希望它看起来像这样:

Root (Type1)
    -sub node1 (Type2)
    --subsub node1 (Type 3)
    -sub node2 (Type 1)
Run Code Online (Sandbox Code Playgroud)

我怎么能做到这一点?使用多重绑定?

c# data-binding wpf treeview textblock

1
推荐指数
1
解决办法
1806
查看次数

如何证明Windows Phone应用程序中TextBlock的文本是正确的?

我想将一个合理的文本放入文本块但是给我一个错误.为什么?我能解决吗?

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <TextBlock Height="220" 
               HorizontalAlignment="Left" 
               Margin="102,174,0,0" 
               Name="textBlock1" 
               Text="TextBlock sdfg asfgbfgb  adf ab afg g " 
               TextAlignment="Justify"
               VerticalAlignment="Top" 
               Width="255" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

windows textblock windows-phone-7

1
推荐指数
1
解决办法
2535
查看次数

垂直旋转的Textblock占据整个宽度,就好像它是水平的一样

我已将TextBlock控件包裹在边框中,这样我就能看到占用空间的东西:

在此输入图像描述

这是XAML:

<Border BorderBrush="Cyan" BorderThickness="3">
    <TextBlock Style="{StaticResource subtitle}" Text="{Binding Title}" >
        <TextBlock.RenderTransform>
            <RotateTransform Angle="90" />
        </TextBlock.RenderTransform>
    </TextBlock>
</Border>
Run Code Online (Sandbox Code Playgroud)

问题是这占用的空间比我需要的多得多,如果我设置一个静态宽度,我得到这个:

在此输入图像描述

有什么建议?

c# wpf xaml textblock text-rotation

1
推荐指数
1
解决办法
2222
查看次数

如何以编程方式移动文本块位置

在WP8中,我想将文本块位置从现有位置移动到新位置(x,y)。我尝试使用

Canvas.SetTop(text1, y);
Canvas.SetLeft(text1, x);
Run Code Online (Sandbox Code Playgroud)

但是它无法更改文本块的位置。有什么最好的办法吗?

c# textblock windows-phone-8

1
推荐指数
1
解决办法
6443
查看次数