2
我在選項卡上的畫布內部有一個網格。 該網格包含一個大的位圖圖像, 我已經(試圖)將網格的大小限制爲該選項卡的大小,並且在網格周圍還有一個5像素的邊距。WPF數據綁定問題
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像素?)
如果你想要網格填充選項卡,那麼你爲什麼把它放在一個畫布?畫布適用於需要以精確尺寸(X,Y)座標精確定位控件的情況 - 對於「填充父項」等動態佈局來說,這沒有好處。 – 2011-05-10 18:10:24