2011-04-15 50 views

回答

3

如果您想要動態剪輯的佈局中存在現有的控件,請使用其SizeChanged事件。例如,讓我們看看剪裁此格: -

<Grid SizeChanged="Grid_SizeChanged" Width="50" Height="20"> 
     <Grid.Clip> 
      <RectangleGeometry /> 
     </Grid.Clip> 
     <TextBlock Margin="0 -9 0 0" Text="This text should not be legible" /> 
    </Grid> 

隨着代碼隱藏: -

private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) 
    { 
     ((RectangleGeometry)((Grid)sender).Clip).Rect = new Rect(0.0, 0.0, e.NewSize.Width, e.NewSize.Height); 
    } 

對於自己的自定義控制,你可能會考慮處理剪輯矩形的ArrangeOverride代替依賴於SizeChanged事件。在這種情況下,您可能希望將RectangleGeometry分配給代碼中的Clip屬性,而不是依賴它在默認模板的Xaml中進行分配。

0

Silverlight支持: 嘗試使用HorisontalAlignment和垂直對齊propertys。將它們設置爲伸展。 如果這不起作用,那麼你將不得不張貼xaml例子。

+0

對齊屬性不影響控件的剪輯區域。 – AnthonyWJones 2011-04-15 20:15:51

+0

如果父母有三角形,Will ClipToBounds會工作嗎?我問這個代碼,如果你的父母總是矩形,那麼對齊屬性是你正在尋找的。 – Sonosar 2011-04-16 06:35:52