我有一个带网格的WPF窗口:
<Grid Name="mainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="700*" />
<ColumnDefinition Width="190*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="220*" />
<RowDefinition Height="450*" />
<RowDefinition Height="160*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
</Grid>
Run Code Online (Sandbox Code Playgroud)
在代码隐藏中,我将一个stackpanel添加到第一列,第二行mainGrid,但我希望stackpanel的最大宽度为第1列的宽度 - 50px.我偶然发现了stkPanel.Width = mainGrid.ColumnDefinitions(1).Width.ToString - 50,但是这会错误:
700*不能转换为double
有没有办法获得网格列的实际宽度,因为它显示在屏幕上以使用我想要的方式,或者我是否设置填充或类似?
谢谢,
马特
我有一个StackPanel比它的父母大的Grid.我确认使用Snoop WPF间谍.该Widths的设置为默认值.如何约束呢?
我不喜欢这个ViewBox解决方案,因为它缩小了我的文字,我希望它被包装/修剪.
根据请求编辑 XAML
<Grid>
<StackPanel
Orientation="Horizontal">
<Border
BorderBrush="Black"
BorderThickness="1"
Width="{ Binding BorderScreenShot }"
Margin="0,-8,0,0">
<Image
ToolTip="Some Text"
Cursor="Hand"
Source="{ Binding Image }"
Stretch="Fill"
Visibility="{ Binding ImageVisibility }"
MouseLeftButtonUp="Image_MouseLeftButtonUp" />
</Border>
<StackPanel
Orientation="Vertical"
Margin="10,0,0,0">
<TextBlock
Text="{ Binding Name }"
TextWrapping="Wrap" />
<TextBlock
Text="{ Binding LongText }"
TextWrapping="Wrap" />
<StackPanel
Orientation="Horizontal">
<TextBlock
Text="{ Binding Category }" />
<TextBlock
Text="{ Binding Version }" />
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud) 我有
<div style="position:relative; width:500px;">
<div style="position:absolute; width:100%"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
子div占用它的父div的100%宽度.有没有办法可以强制它采取100%宽度的身体而不是父div.我需要在上面的代码中进行相对和绝对定位.
我有一个网站的以下HTML布局(由网络解决方案nsCommerceSpace提供)我正在设计一个主题:
<div id="ctl00_breadcrumb" class="breadcrumb">
<span id="ctl00_breadcrumbContent">
<span><a href="/">[Name of Webstore]</a></span>
<span> > </span>
<span><a href="/page.aspx">Page</a></span>
<span> > </span>
<span>Here is a very long title of a product that is causing me much frustration because it jumps out of place.</span>
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
其中包含的span标签<span> > </span>会自动生成以分隔每个项目.
这是我的问题的小提琴:http://jsfiddle.net/5fvmJ/
有没有办法可以让最后一个SPAN标签填满空白区域,只有当它击中右侧时才会结束?我只是overflow: hidden;用来隐藏额外的文字.
有任何想法吗?我知道所有SPAN都让这很难,但它是我无法改变的网站的内置功能.
我有一个带有两个标签页的TabControl.

如何使标签页适合TabControl的宽度,如下面的屏幕截图所示.

我尝试使用以下代码行,但它也不起作用.
tabControl1.SizeMode = TabSizeMode.FillToRight;
Run Code Online (Sandbox Code Playgroud) 我有一个包含3个图像视图的水平线性布局.每个图像视图包含200x200像素的相同图像.这是我的布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image200" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image200" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image200" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是它的样子:

注意左边的第三个图像是如何调整大小我假设的,因为没有足够的空间来容纳3x 200像素宽的图像.
我宁愿发生的不是仅缩小最后一张图像,而是将所有三张图像均匀调整大小以使它们都适合整个屏幕.如何设置我的布局以均匀地适合所有三个图像?
谢谢
更新 - 在更改我的设置后,这是什么样的事情:

请注意,图像视图周围的边框仍然是200像素高.为什么会这样?
我现在有一个UILabel,UILabel.text值会定期更改.
我遇到的问题是,如果每次UILabel.text值更改,UILabel宽度将根据标签的内容而更改.
我怎样才能解决这个问题?这是我现在的代码:
outputLabel.text = errorMessage;
outputLabel.hidden = NO;
[outputLabel sizeToFit];
Run Code Online (Sandbox Code Playgroud)
更新 我使用sizeToFit的原因是因为我需要自动更改高度.
谢谢,
彼得
我希望div具有相对于font-size的border-width,所以我设置例如border-width: 0.1em;。但是,如果字体大小太小,则将边框缩小为时,不会显示边框0.5px。这当然不是我想要的。有没有机会将最小边框宽度设置为1px?
div {
border: 0.1em solid black;
}
Run Code Online (Sandbox Code Playgroud) 我有一个稍微不寻常的CSS挑战需要克服.
我有一个两列布局,其中左列的宽度由主图像的宽度设置,右边允许填充剩余的空间.主图像下方有一个容器,其自然宽度可能大于主图像.但是,我希望这个div与主图像的宽度相同,并且要隐藏溢出.以下是我尝试这样做的努力:
.outer {
margin-right: 5px;
position: relative;
}
.left {
float: left;
}
.right {
width: auto;
overflow: hidden;
}
.contentOuter {
overflow: hidden;
}
.content {
width: 500px;
}
.inner {
background-color: grey;
color: white;
width: 100%;
height: 150px;
}Run Code Online (Sandbox Code Playgroud)
<div class="outer left">
<div class="image">
<img src="http://placehold.it/350x150" />
</div>
<div class="contentOuter">
<div class="content">
<img src="http://placehold.it/500x50" />
</div>
</div>
</div>
<div class="outer right">
<div class="inner">
Hello world!
</div>
</div>Run Code Online (Sandbox Code Playgroud)
但正如您所看到的.contentOuter,无论我尝试什么,都会延伸到其内容的宽度.
我有一个主要的警告是,除了.content有一个固定的宽度,我不希望我的CSS中有任何其他硬编码宽度; 一切都应该是完全流动的,并且柱子的尺寸由尺寸决定.image img. …
我正在尝试制作一个(1 行,3 列)条形图数组,它们都具有相同的条形宽度。
所有三个条形图都有不同数量的观测值,因此每个图的条形宽度最终都不同(即,具有最多观测值的图形具有最窄的条形,而具有最少观测值的图形具有最宽的条形)。我从barplot {graphics} R文档中了解到,
“除非
xlim指定,否则指定单个值将没有可见效果”
但是,我x labels是字符串,所以我不确定如何指定xlim. 我不介意我的图的宽度是否不同,但是我需要以某种方式指定它吗?
这是一些假数据和我正在使用的代码……谢谢你的帮助。
height4plot1 <- c(1,6,9,2,3,10,7,15)
names4plot1 <- c("P1","P2","P3","P4","P5","P6","P7","P8")
height4plot2 <- c(5,4,10,2)
names4plot2 <- c("M1","M2","M3","M4")
height4plot3 <- c(4,12)
names4plot3 <0 c("U1","U2")
par(mfrow=c(1,3),
mar=c(10,5,2,1),
cex.axis=0.7,
mgp=c(3,0.5,0))
barplot(height4plot1,
names.arg=names4plot1,
las=3,
axes=TRUE,
axisnames=TRUE,
ylab="YLAB",
ylim=ylim,
plot=TRUE,
main="PLOT1",
width=1)
barplot(height4plot2,
names.arg=names4plot2,
las=3,
axes=TRUE,
axisnames=TRUE,
ylim=ylim,
plot=TRUE,
main="PLOT2",
width=1)
barplot(height4plot3,
names.arg=names4plot3,
las=3,
axes=TRUE,
axisnames=TRUE,
ylim=ylim,
plot=TRUE,
main="PLOT3",
width=1)
Run Code Online (Sandbox Code Playgroud) width ×10
css ×4
html ×3
wpf ×2
.net ×1
android ×1
border ×1
c# ×1
css-float ×1
grid ×1
imageview ×1
inheritance ×1
ios ×1
minimum-size ×1
objective-c ×1
plot ×1
r ×1
stackpanel ×1
tabcontrol ×1
tabpage ×1
uilabel ×1