我有GridLayout5列3行.现在我可以插入任意子视图,这很棒.更好的是,我可以分配columnSpan=2给某个项目以便将其扩展到2列(与rowSpan相同).
现在的问题是,我不能以编程方式(即在运行时)分配rowSpan或columnSpan.一些搜索建议这样的事情:
layoutParams.columnSpec = GridLayout.spec(0, columnSpan);
Run Code Online (Sandbox Code Playgroud)
但我不太清楚spec的参数是什么意思(开始和大小).此时的文档也很差.
任何帮助都非常感谢!
我使用的tableLayoutPanel是由两行组成的.在第一行我想要两列,在第二行我只需要一列.我怎样才能做到这一点?
我在http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5c7f5cdf-4351-4969-990f-29ce9ec84b87/上问了一个问题,但对一个奇怪的行为仍然缺乏一个很好的解释.
运行以下XAML显示第0列中的TextBlock宽度大于100,即使该列设置为宽度100.我认为奇怪的可能与它被包装在ScrollViewer中有关,但我不知道为什么.如果我在列上设置MaxWidth,它可以正常工作,但设置Width不会.
我感谢任何解释!这对我来说真是一个难题.
<Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Width="300">
<ScrollViewer HorizontalScrollBarVisibility="Auto" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock x:Name="textBlock" Text="{Binding ElementName=textBlock, Path=ActualWidth}" />
<TextBlock Text="column 1" Grid.Column="1" />
<TextBlock Grid.Row="1" Grid.ColumnSpan="3" Text="text here that is wider than the first two columns combined" />
</Grid>
</ScrollViewer>
</Window>
Run Code Online (Sandbox Code Playgroud) 我有一个我在WPF中编写的自定义用户控件来显示一些数据.我想在列表中显示此usercontrol,但我还想提供多个列标题(匹配用户cotrol上的一些属性),以便用户可以对usercontrol中包含的属性进行排序.
我不确定最好的办法.
我目前有一个ListBox显示这些用户控件,但ListBox没有标题,我无法弄清楚如何在ListBox上放置多个标题.
理想情况下,我喜欢这样的事情:
Header1 Header2 Header3 Header4
[UserControlThatSpansAllFourColumns]
Run Code Online (Sandbox Code Playgroud)
我的另一个想法是使用DataGrid并以某种方式让每个项目跨越多个列,但到目前为止,我也无法解决这个问题.
如果有人有任何提示,我会欢迎他们!
考虑以下python脚本
#!/usr/bin/env python
from Tkinter import Tk, Label
width = SOME_VALUE_HERE
root = Tk()
label1 = Label(root, text='1 columns wide')
label2 = Label(root, text='%i columns wide' % width)
label1.grid()
label2.grid(row=0,column=1,columnspan=width)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
当我运行它时,无论为“SOME_VALUE_HERE”设置什么值,两个标签都占据窗口的一半,无论是否调用了 Grid.columnconfigure,或者是否在 grid() 中使用了粘性参数。
除非我忽略了一些东西,否则我会认为设置 columnspan 会强制第二个标签的宽度是第一个标签的 'SOME_VALUE_HERE' 倍。
我误解了网格的工作原理吗?我将如何实现这种行为?
在网格中为UIElement设置列跨度非常容易.
Grid.SetColumnSpan(extBorder, gridFormular.ColumnDefinitions.Count());
Run Code Online (Sandbox Code Playgroud)
但阅读元素的ColumnSpan是什么意思?怎么做?
columnspan ×6
grid ×4
wpf ×3
android ×1
c# ×1
datagrid ×1
grid-layout ×1
html ×1
html-table ×1
listbox ×1
merge ×1
tkinter ×1
winforms ×1
xaml ×1