这应该是这么简单 - 我一直在我的桌子上长时间试图让一个看似简单的任务工作(让我觉得WPF不直观或有缺陷)......
在任何情况下,我都有一个设置为水平方向的Stackpanel.在里面我有两个TextBlocks.我希望第二个在右边显示它的文本.
我该如何完成它?
这一切让我想起了为什么我离开了Silverlight.:p
以下片段:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center">
<Label Content="Name:"/>
<Label Content="Itzhak Perlman" FontSize="44"/>
</StackPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
呈现以下内容:
有没有什么方法可以设置标签的样式,以便他们的文本底部应该对齐?
我对TextBlocks也有同样的问题.
注意:由于我一直在努力解决这个问题,请发布您知道可行的某些答案.
我已经尝试过:VerticalAlignment,VerticalContentAlignment,Padding,Margin.还有什么我不知道的吗?
我已经阅读过这篇文章,但它没有谈到不同字体大小的情况.
更新:问题是,即使Padding设置为0,在ContentPresenter区域内的字体周围仍然存在不确定的空间.这个空间因字体大小而异.如果我可以控制这个空间,我会处于更好的状态.
谢谢
在我的C#独立应用程序中,我想让用户点击一个可以启动他们喜爱的浏览器的链接.
System.Windows.Controls.TextBlock text = new TextBlock();
Run run = new Run("Link Text");
Hyperlink link = new Hyperlink(run);
link.NavigateUri = new Uri("http://w3.org");
text.Inlines.Add(link);
Run Code Online (Sandbox Code Playgroud)
链接显示正确.
当我将鼠标移到它上面时,链接变为红色.
问题:当我点击它时,没有任何反应.
我忘记了什么吗?我是否需要实现某种方法才能真正打开链接?
好的,这是我的XAML:
<TextBlock Text="{Binding Path=InstanceName}"></TextBlock>
Run Code Online (Sandbox Code Playgroud)
如果InstanceName
是null或空字符串,我想要Visibility="Collapsed"
.否则我想要Visibility="Visible"
.我该怎么办?
我有一个我创建的动态Datagrid.我通过后面的代码为它创建每一列.我想在不编辑时在文本块上显示的列上遇到麻烦,但在编辑时作为组合框显示.我有一个ObservableCollection of Transactions.每个交易都有一个名为"账户"的类型.这是我到目前为止:
private DataGridTemplateColumn GetAccountColumn()
{
// Create The Column
DataGridTemplateColumn accountColumn = new DataGridTemplateColumn();
accountColumn.Header = "Account";
Binding bind = new Binding("Account");
bind.Mode = BindingMode.TwoWay;
// Create the TextBlock
FrameworkElementFactory textFactory = new FrameworkElementFactory(typeof(TextBlock));
textFactory.SetBinding(TextBlock.TextProperty, bind);
DataTemplate textTemplate = new DataTemplate();
textTemplate.VisualTree = textFactory;
// Create the ComboBox
bind.Mode = BindingMode.OneWay;
FrameworkElementFactory comboFactory = new FrameworkElementFactory(typeof(ComboBox));
comboFactory.SetValue(ComboBox.DataContextProperty, this.Transactions);
comboFactory.SetValue(ComboBox.IsTextSearchEnabledProperty, true);
comboFactory.SetBinding(ComboBox.ItemsSourceProperty, bind);
DataTemplate comboTemplate = new DataTemplate();
comboTemplate.VisualTree = comboFactory;
// Set the Templates to the Column
accountColumn.CellTemplate …
Run Code Online (Sandbox Code Playgroud) 我有TextBlock动态添加Inlines(基本上是一堆斜体或粗体的Run对象).
在我的应用程序中,我有搜索功能.
我希望能够突出显示正在搜索的TextBlock文本.
通过突出显示我的意思是更改TextBlock文本颜色的某些部分(请记住,它可能一次突出显示几个不同的Run对象).
但它接缝非常不稳定:(
有没有简单的方法来解决这个问题?
我在使用TextWrapping在此示例中工作时遇到问题.谁能看到我在这里错了什么?
<ListView Name="listViewReportedException" ItemsSource="{Binding ExceptionDetails}">
<ListView.View>
<GridView>
<GridViewColumn Header="Time" DisplayMemberBinding="{Binding Thrown}" Width="150" />
<GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="385">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding}" Width="385"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Recover action" DisplayMemberBinding="{Binding Action}" Width="90"/>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud) 我有一个带有两个TextBlock控件(堆叠)的WPF DataTemplate,然后是一些其他元素.由于一些复杂的布局代码,我需要知道两个TextBlock元素的高度,以便我可以绘制一些花哨的连接线,并排列其他控件等.
如果我知道进入TextBlocks的文本,我知道字体等,是否有某种方法可以计算或测量这些TextBlocks的高度而不实际呈现它们?
textblock ×10
wpf ×10
c# ×2
.net-3.5 ×1
binding ×1
combobox ×1
datagrid ×1
datatemplate ×1
highlighting ×1
hyperlink ×1
layout ×1
measure ×1
navigateuri ×1
stackpanel ×1
visibility ×1
word-wrap ×1
xaml ×1