如何垂直对齐a Label
和TextBlock
at Top
以使它们的第一行文本排成一行?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Column="0" VerticalAlignment="Top">Some Label:</Label>
<TextBlock Grid.Column="0" VerticalAlignment="Top">Some text<TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我这个:
垂直未对齐的Label和TextBlock文本http://img156.imageshack.us/img156/4940/labeltextblock.png
我在文本块中有一行文字,内容如下:
"检测到[手势],准确度为[准确度]"
在WPF中,我是否可以更改文本块中元素的颜色?我可以将文本块设置为多种颜色吗?例如,我希望整个TextBlock是黑色的,除了手势名称,我想要是红色的.
这可能在WPF中吗?
如何将2个属性绑定到单个TextBlock.Text(例如,名字和姓氏或当前值和最大值)?
就像是:
// IValueConverter
public object Convert( .... )
{
return string.Format("{0} (max: {1})", currentValue, maxValue);
}
Run Code Online (Sandbox Code Playgroud)
问题是我想在TextBlock.Text进行更新currentValue
或 maxValue
改变.那么如何使用数据绑定监听2个或更多属性的更改?
除了用户之外还有其他方式IValueConverter
吗?
我正在用C#开发window phone 7应用程序.我是窗口手机7应用程序的新手.我也是银光的新手.我想动态生成Texblock的粗体文本.我想仅为文本的某些部分生成粗体文本.我使用以下代码
IncometextBlock.Text = "Income entries on " + selectedDate.ToShortDateString() + " Page - "+SelectedButtonName+"";
Run Code Online (Sandbox Code Playgroud)
我希望输出为
" 2011 年1月21日收入条目页面 - A "
我想要上面的输出.如何制作上述要求的粗体文字?能否请您提供我可以解决上述问题的任何代码或链接.如果我做错了什么,请指导我.
基本上我目前在我的大学做最后一年的项目,我接触表面2.0 WPF.
我的项目是一个游戏,如果用户错误地回答问题,下一个问题将被轮换以使其更加困难.但我不确定该怎么做.我在msdn microsoft中看到了一个例子,但它只显示了XAML代码.我需要C#代码.
这是XAML示例.
http://msdn.microsoft.com/en-us/library/ms754028.aspx
最后一个例子
这是我的验证码的一部分.如果用户回答错误,我需要激活动画.
if (surfaceRadioButton1.IsChecked == true)
{
user_answer = (string)surfaceRadioButton1.Content;
textBlock2.Text = validateAnswer(user_answer, answer);
retreiveYellowQns();
if (textBlock2.Text.Equals("Correct"))
{
yellow_coord = yellow_coord + 50;
Canvas.SetLeft(car, yellow_coord);
Canvas.SetTop(car, 289);
}
else
{
if (yellow_coord <= 330)
{
yellow_coord = 330;
Canvas.SetLeft(car, yellow_coord);
Canvas.SetTop(car, 289);
}
else
{
yellow_coord = yellow_coord - 50;
Canvas.SetLeft(car, yellow_coord);
Canvas.SetTop(car, 289);
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很高兴,提前谢谢.
我尝试绑定Text
属性TextBlock
到我的属性,但文本不更新.
XAML
<Window x:Name="window" x:Class="Press.MainWindow"
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"
Title="Press analyzer" Height="350" Width="525" ContentRendered="Window_ContentRendered"
d:DataContext="{d:DesignData MainWindow}">
...
<StatusBar Name="StatusBar" Grid.Row="2" >
<TextBlock Name="StatusBarLabel" Text="{Binding Message}"/>
</StatusBar>
</Window>
Run Code Online (Sandbox Code Playgroud)
C#
public partial class MainWindow : Window, INotifyPropertyChanged
{
private string _message;
public string Message
{
private set
{
_message = value;
OnPropertyChanged("Message");
}
get
{
return _message;
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged; …
Run Code Online (Sandbox Code Playgroud) 我希望TextBlock中的所有字符都以大写形式显示
<TextBlock Name="tbAbc"
FontSize="12"
TextAlignment="Center"
Text="Channel Name"
Foreground="{DynamicResource {x:Static r:RibbonSkinResources.RibbonGroupLabelFontColorBrushKey}}" />
Run Code Online (Sandbox Code Playgroud)
字符串通过Binding获取.我不想在字典本身中将字符串设为大写.
我正在改变TextDecoration
这种方式的颜色:
<Grid Background="{x:Null}"
Margin="10,0,10,0">
<TextBlock Text="{Binding Value}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Style="{StaticResource SWMRegularTextBlockStyle}"
Margin="0"
FontSize="{DynamicResource RegularFontSize}"
x:Name="tb" />
<Line VerticalAlignment="Center"
HorizontalAlignment="Center"
Visibility="{Binding InStock, Converter={StaticResource ReverseBooleanToVisiblity}}"
Stroke="Red"
Margin="0"
StrokeThickness="2"
X1="1"
Stretch="Fill"
Width="{Binding ActualWidth, ElementName=tb, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
但是当Text
有两条线路失败时.请帮我改变TextDecoration的颜色.提前致谢.
注意:我想要TextBlock
不同颜色的前景和透视线.
我正在使用WPF网格作为窗口的布局.它有两列和任意数量的行.第一列专门用于标签,第二列用于用户输入字段(例如TextBox,ComboBox等).我的要求是:
我试过下面的XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="50" MaxWidth="180" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="First Name" TextTrimming="CharacterEllipsis" />
<TextBox Grid.Column="1" Text="{Binding FirstName}" />
<TextBlock Grid.Row="1" Text="Family Name" TextTrimming="CharacterEllipsis" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding FamilyName}" />
<TextBlock Grid.Row="2" Text="Label That Won't Fit in 180 units" TextTrimming="CharacterEllipsis" />
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Text}" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
我希望第三行标签"不符合180个单位的标签"将被截断为"标签赢得......"之类的东西.相反,它被剪切到"标签不会",一半的"t"丢失.
我尝试了一种在网络上找到的不同方法.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="LabelColumn" Width="Auto" MinWidth="50" MaxWidth="180" />
<ColumnDefinition Width="*" /> …
Run Code Online (Sandbox Code Playgroud) 有没有办法检测文本块中的换行符数TextWrapping="Wrap"
?
我正在考虑使用非等宽字体.我需要这个,因为我正在创建一个新的,个性化的MessageBox窗口,它有一个大文本标题,动画,我的应用程序的徽标和我的应用程序的主题.
很明显,我需要根据正文消息的LineBreak数量来改变窗口的大小 - 类似于默认MessageBox窗口的行为方式.
textblock ×10
wpf ×7
xaml ×5
c# ×4
binding ×3
animation ×1
data-binding ×1
dynamic-data ×1
grid ×1
label ×1
pixelsense ×1
silverlight ×1
uppercase ×1
word-wrap ×1