我有最困难的时间来解决这个问题:说我有两个Button和三个TextBlocks.我想要任一按钮在所有TextBlocks上触发一个简单的故事板.目前我正在尝试定义包含Storyboard的通用Textblock样式,然后触发器来自任何Button单击.这是我最接近的但应用程序在启动时崩溃了......我在这里没有错:
<Window.Resources>
<Style TargetType="TextBlock" >
<Setter Property="Foreground" Value="Blue" />
<Style.Resources>
<Storyboard x:Key="TextBlockOpacity" Storyboard.TargetProperty="Opacity">
<DoubleAnimation From="0" To="1" />
</Storyboard>
</Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)
<Window.Triggers>
<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="button">
<BeginStoryboard Storyboard="{StaticResource TextBlockOpacity}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="LayoutRoot">
<Button x:Name="button" HorizontalAlignment="Left" Margin="51,54,0,0" VerticalAlignment="Top" Width="96" Height="45" Content="Button"/>
<TextBlock x:Name="textBlock1" Margin="228,54,172,0" VerticalAlignment="Top" Height="45" FontSize="26.667" Text="TextBlock" TextWrapping="Wrap" />
<TextBlock x:Name="textBlock2" Margin="228,103,172,0" VerticalAlignment="Top" Height="45" FontSize="26.667" Text="Hello" TextWrapping="Wrap"/>
</Grid>
Run Code Online (Sandbox Code Playgroud) 我是wpf的新手,我想在wpf文本块中的一行显示文本.例如.:
<TextBlock
Text ="asfasfasfa
asdasdasd"
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
TextBlock默认显示两行,
但我只想在一行中像"asafsf asfafaf"一样.我的意思是在一行中显示所有文本,即使文本中有多行,
我该怎么办?
这是我的XAML:
<TextBlock Name="SeverityText"
Grid.Column="1"
Grid.Row="0"
Foreground="Red">
<TextBlock.Triggers>
<DataTrigger Binding="{Binding Path=Severity}">
<DataTrigger.Value>
<sm:Severity>Warning</sm:Severity>
</DataTrigger.Value>
<Setter TargetName="SeverityText"
Property="Foreground"
Value="Yellow" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=Severity}">
<DataTrigger.Value>
<sm:Severity>Information</sm:Severity>
</DataTrigger.Value>
<Setter TargetName="SeverityText"
Property="Foreground"
Value="White" />
</DataTrigger>
</TextBlock.Triggers>
<TextBlock>Severity:</TextBlock>
<TextBlock Text="{Binding Path=Severity}" />
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
这是我的错误消息:
在"ContentPresenter"类型上找不到静态成员"ForegroundProperty".
sm:严重性是我导入的枚举.
嗨Guyz我有一个固定宽度的WPF TextBlock说100,如果字符串不适合宽度,则最后一个字符被切断,因为所有字符的大小都不一样.我不想剪切字符,而是想从那里跳过文本,只显示没有字符截止的文本.
您好我正在尝试为文本块提供默认值,如果返回的结果为null
这是我正在尝试的!
返回的只是我设置的字符串格式!
<TextBlock x:Name="NameTxtBlock" Grid.Column="0" Margin="0,0,40,0" FontFamily="Segoe UI" FontSize="14" Text="{Binding Name, StringFormat='Item Name: {0}'}" Padding="2">
<TextBlock.Style>
<Style TargetType="TextBlock" >
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=NameTxtBlock, Path=Text}" Value="{x:Null}">
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="Text" Value="No Name Found" />
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=NameTxtBlock, Path=Text}" Value="{x:Static System:String.Empty}">
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="Text" Value="No Name Found" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
Run Code Online (Sandbox Code Playgroud) 是否可以在TextBlock控件中使用边距文本?
我在textBlock控件上的样式如下:
<Style x:Key="InfosStyle" TargetType="{x:Type TextBlock}">
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Height" Value="35"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Justify"/>
<!--<Setter Property="BorderThickness" Value="1"/>-->
<!--<Setter Property="BorderBrush" Value="#BFE3FE"/>-->
<Setter Property="Background" Value="#BFE3FE"/>
<Setter Property="Margin" Value="2,4,0,1" />
</Style>
Run Code Online (Sandbox Code Playgroud)
结果在这里:
为了考试,我想在textBlock中对齐或设置文本边距.
现在:| Chatuje到| _Chatuje
我想在TextBlock的左侧有一些空闲空间.
可用空间TextOfTextBlock
没有
TextOfTextBlock
我有一个TextBlock和一个Rectangle,它们都位于一个空的WPF4窗口中.TextBlock的Foreground和Rectangle的Fill都设置为值为#80800000的SolidColorBrush.
这就是它的样子:
Rectangle的颜色是正确的(50%透明栗色),但TextBlock呈现平坦的灰色.这是怎么回事?
编辑:这是XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBlock Foreground="#80800000" Height="100" HorizontalAlignment="Left" Margin="47,39,0,0" Text="TextBlock" VerticalAlignment="Top" Width="266" FontFamily="Arial" FontWeight="Bold" FontSize="56" />
<Rectangle Fill="#80800000" Height="100" HorizontalAlignment="Left" Margin="71,174,0,0" Stroke="{x:Null}" VerticalAlignment="Top" Width="200" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 这个全局样式在App.xaml中声明:
<Style TargetType="TextBlock">
<Setter Property="FontFamily" Value="Times New Roman"/>
<Setter Property="FontSize" Value="20"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
在一个窗口中,我试图在本地覆盖这个:
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="FontSize" Value="60" />
</Style>
Run Code Online (Sandbox Code Playgroud)
还有这个:
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="60" />
</Style>
Run Code Online (Sandbox Code Playgroud)
但没有任何作用.我仍然坚持使用App.xaml中设置的样式.有谁知道什么可能干扰这个?如果我从App.xaml中删除该全局,我可以在本地设置我想要的任何内容.如果我改变全局中的值,它会全局反映出来,所以我认为没有任何一个全球性的地方与之相冲突.我搜索TargetType="TextBlock"
并没有得到任何东西.
有任何想法吗?
我会跳到追逐:有没有办法告诉WPF TextBlock
自己测量它的大小在它改变时不会改变FontWeight
?
我有一个TextBlock
根据样式动态更改字体权重.该TextBlock
是内部的RadioButton
所以检查时,它是勇敢的,否则正常:
<Style x:Key="BoldWhenChecked" TargetType="RadioButton">
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="TextElement.FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style
Run Code Online (Sandbox Code Playgroud)
以下是单选按钮本身:
<StackPanel Orientation="Horizontal">
<RadioButton Style="{StaticResource BoldWhenChecked}">
<TextBlock Text="Item 1" />
</RadioButton>
<RadioButton Style="{StaticResource BoldWhenChecked}">
<TextBlock Text="Item 2" />
</RadioButton>
<RadioButton Style="{StaticResource BoldWhenChecked}">
<TextBlock Text="Item 3" />
</RadioButton>
etc...
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
不幸的是,由于我没有使用固定宽度的字体,TextBlock
当字体重量改变时,改变的宽度,并且整个单选按钮面板相应地移动,这在视觉上是不和谐的.
我有一个TextBlock
WPF应用程序.
的(Text
,Width
,Height
,TextWrapping
,FontSize
,FontWeight
,FontFamily
的这个)性质TextBlock
是动态的(由用户在运行时输入).
每次用户更改以前的某个属性时,都会在运行时更改其Content
属性TextBlock
.(一切都好,直到这里)
现在,我需要TextBlock
根据之前指定的属性获取该行.
这意味着我需要TextWrapping
算法将产生的线条.
换句话说,我需要在一个单独的字符串中的每一行,或者我需要一个带Scape序列的字符串\n
.
有什么想法吗?
textblock ×10
wpf ×10
c# ×2
alignment ×1
alpha ×1
brush ×1
button ×1
coding-style ×1
datatrigger ×1
foreground ×1
margin ×1
opacity ×1
triggers ×1
word-wrap ×1
xaml ×1