【发布时间】:2011-05-10 16:36:43
【问题描述】:
我在选项卡上的画布内有一个网格。 网格包含一个大的位图图像, 我已经(试图)将网格的大小绑定到选项卡的大小,并且网格周围还有五个像素的边距。
imageTab.cs
public ImageTab(SendInfo sendInfo, int numImge, int numAccs)
{
imageDisplay = new ImageDisplay(sendInfo, numImge, numAccs);
imageDisplay.ClipToBounds = true;
CreateCanvas();
}
private void CreateCanvas()
{
Canvas canvas = new Canvas();
canvas.Children.Add(imageDisplay);
this.AddChild(canvas);
}
ImageDisplay.xaml
<UserControl x:Class="MyProj.ImageDisplay">
<Grid Margin="5,5,5,5" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=TabControl, AncestorLevel=1}, Path=ActualHeight}">
<Image/>
</Grid>
</UserControl>
网格从选项卡区域的底部略微脱落,导致图像底部被截断。 我的数据绑定有问题,我需要对其应用某种偏移量吗? (标签大小 - 10 像素的边距?)
【问题讨论】:
-
如果你想让网格填充标签,那你为什么要把它放在 Canvas 里面呢?画布适用于您需要将控件定位在具有精确尺寸的精确 (X,Y) 坐标上的情况——它不适合“填充父级”等动态布局。
标签: c# wpf data-binding grid tabcontrol