有没有办法告诉WPF中的组件占用100%的可用空间?
喜欢
width: 100%;
Run Code Online (Sandbox Code Playgroud)
在CSS中
我有这个XAML,我不知道如何强制Grid占用100%的宽度.
<ListBox Name="lstConnections">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="LightPink">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=User}" Margin="4"></TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Password}" Margin="4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Path=Host}" Margin="4"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
结果看起来像
替代文字http://foto.darth.cz/pictures/wpf_width.jpg
我把它做成了粉红色,这显然需要多少空间.我需要使粉红色网格100%宽度.
在WPF中创建UserControl时,我发现给它一些任意的Height和Width值很方便,这样我就可以在Visual Studio设计器中查看我的更改.但是,当我运行控件时,我希望高度和宽度未定义,以便控件将展开以填充我放入的任何容器.如何在不必删除高度和宽度值之前实现相同的功能建立我的控制?(或者不在父容器中使用DockPanel.)
以下代码演示了此问题:
<Window x:Class="ExampleApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="clr-namespace:ExampleApplication3"
Title="Example" Height="600" Width="600">
<Grid Background="LightGray">
<loc:UserControl1 />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
以下定义UserControl1在设计时合理显示,但在运行时显示为固定大小:
<UserControl x:Class="ExampleApplication3.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid Background="LightCyan" />
</UserControl>
Run Code Online (Sandbox Code Playgroud)
以下定义UserControl1在设计时显示为点,但Window1在运行时展开以填充父级:
<UserControl x:Class="ExampleApplication3.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="LightCyan" />
</UserControl>
Run Code Online (Sandbox Code Playgroud) 我在div中有一个to-columns表:
<div>
<table>
<tbody>
<tr>
<td class="action" >
<a> ? </a>
</td>
<td class="content">
<p>Bigger text...(variable size).......</p>
</td>
</tr>
<tr>
<td class="action" >
<a> ? </a><a> ? </a>
</td>
<td class="content">
<p>Bigger text...(variable size).......</p>
</td>
</tr>
... same structure in all the table
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望"action"列适合内容,而"content"列则需要剩余的可用空间.使用右对齐,"action"列看起来会更好.桌子也应该适合容器宽度的100%.
有没有办法在不修复列宽的情况下这样做?
我试过这个:
table .action
{
width:auto;
text-align:right;
}
table
{
border-collapse:collapse;
border-spacing:0;
width:100%;
}
Run Code Online (Sandbox Code Playgroud)
但左栏占据了一半的表......
我希望slickgrid根据最宽的内容或标题文本自动调整列的大小 - 以较宽者为准.简单来说,我希望它在列大小调整时模拟常规HTML表的默认行为.我怎么能在slickgrid中做到这一点?
我在支持库26中添加了新的自动调整功能.我阅读了一个文档,可以在这里找到:https: //developer.android.com/preview/features/autosizing-textview.html
我认为它应该以这种方式工作:您可以使用以下属性启用自动调整大小:app:autoSizeTextType="uniform".我认为TextView应该使用所有可用空间来显示整个文本(不仅仅是一个部分 - 它不应该被裁剪)并且textSize应该尽可能大.如果您需要限制文本的最大或最小大小,则可以使用以下两个属性:
app:autoSizeMinTextSize="XXsp" // (you can also use px or dp values.)
Run Code Online (Sandbox Code Playgroud)
要么
app:autoSizeMaxTextSize="XXsp"
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.假设我需要一个宽度为56dp的TextView.我有不同长度的文本,我想将这些文本设置为此TextView.它应该自动调整大小,以便尽可能显示整个文本(所有字符+未裁剪)textSize.
这是我的TextView:
<android.support.v7.widget.AppCompatTextView
android:id="@+id/vName"
style="@style/TextView.AutoSize"
android:layout_width="56dp"
android:gravity="bottom|center_horizontal"
android:maxLines="1"
app:autoSizeMinTextSize="1px"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toTopOf="@id/vGuideline"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
Run Code Online (Sandbox Code Playgroud)
不幸的是,文本视图被裁剪.我想将此String设置为上面TextView的文本:"Groupa"但结果如下:

(TextView位于ConstraintLayout内部,带有黄色圆圈背景.)
如您所见,textview根本没有调整大小.你知道该怎么办吗?
谢谢.
android autosize textview android-support-library android-8.0-oreo
你如何设置Height="*"和Height="Auto"代码背后?
我正在使用PHPExcel导出数据以供下载.打开下载的文件时,如果单元格数量较大,则显示"#######"而不是值编号.我尝试setAutoSize()了每个列,然后调用,$sheet->calculateColumnWidths()但它仍然没有变化.我在这里看到calculateColumnWidths(),@ Mark Baker说"calculateColumnWidths()将值增加5%,以确保整个列适合".如果单元格中的数字长度超过5%,那么似乎已经解决了问题
更新 这是我自动调整列的功能:
function autoFitColumnWidthToContent($sheet, $fromCol, $toCol) {
if (empty($toCol) ) {//not defined the last column, set it the max one
$toCol = $sheet->getColumnDimension($sheet->getHighestColumn())->getColumnIndex();
}
for($i = $fromCol; $i <= $toCol; $i++) {
$sheet->getColumnDimension($i)->setAutoSize(true);
}
$sheet->calculateColumnWidths();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一种方法来调整多行文本的大小TextView,使其适合于(在X和Y维度)的范围内TextView.
目前,我有一些东西,但它所做的只是调整文本大小,使文本的第一个字母/字符填充尺寸TextView(即只有第一个字母是可见的,而且它是巨大的).我需要它来适应TextView边界内的所有文本行.
这是我到目前为止:
public static void autoScaleTextViewTextToHeight(TextView tv)
{
final float initSize = tv.getTextSize();
//get the width of the view's back image (unscaled)....
float minViewHeight;
if(tv.getBackground()!=null)
{
minViewHeight = tv.getBackground().getIntrinsicHeight();
}
else
{
minViewHeight = 10f;//some min.
}
final float maxViewHeight = tv.getHeight() - (tv.getPaddingBottom()+tv.getPaddingTop())-12;// -12 just to be sure
final String s = tv.getText().toString();
//System.out.println(""+tv.getPaddingTop()+"/"+tv.getPaddingBottom());
if(minViewHeight >0 && maxViewHeight >2)
{
Rect currentBounds = new Rect();
tv.getPaint().getTextBounds(s, 0, s.length(), currentBounds);
//System.out.println(""+initSize);
//System.out.println(""+maxViewHeight);
//System.out.println(""+(currentBounds.height())); …Run Code Online (Sandbox Code Playgroud) autosize ×10
wpf ×4
android ×2
textview ×2
width ×2
c# ×1
css ×1
html ×1
html-table ×1
iframe ×1
javascript ×1
php ×1
phpexcel ×1
resize ×1
slickgrid ×1
tablecolumn ×1
wpf-controls ×1
xaml ×1