是否可以使网格控件充当容器控件

时间:2011-07-27 16:59:56

标签: silverlight xaml windows-phone-7

我正在使用Silverlight,最终使用Silverlight作为手机。

我要做的是创建一个包含子控件的带边框容器。当超出网格控件的范围时,子控件不应该是可见的。

这可能吗?我知道我可以从路径创建剪辑,但这是唯一的方法。

我确实使用了一个滚动容器,它看起来很有用......

这是xaml。我期待的是在应用程序运行时第二个按钮不可见。

<Grid x:Name="LayoutRoot" Background="White" >
    <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Height="197" Width="241" d:LayoutOverrides="HorizontalAlignment, VerticalAlignment">
        <Button Content="Button" Margin="25,42,101,81"/>
        <Button Content="Button" Height="76" Margin="25,0,63,-83" VerticalAlignment="Bottom"/>
    </Grid>
</Grid>

3 个答案:

答案 0 :(得分:2)

使用UIElement.ClipToBounds

http://msdn.microsoft.com/en-us/library/system.windows.uielement.cliptobounds.aspx

<Grid ClipToBounds="True">

    ...

</Grid>

答案 1 :(得分:0)

因为您似乎要问的是Grid控件默认是如何工作的,例如:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <DockPanel Margin="50" Background="Azure" > 
    <Grid>
      <TextBlock>The only part of this control that gets rendered is that which is inside the bounds of the Grid.</TextBlock>
    </Grid>
  </DockPanel>
</Page>

我只能假设你在问别的东西。但是什么?

答案 2 :(得分:0)

我找到了一个解决方案但又喜欢使用其他解决方案。我使用了一个scrollviewer并隐藏了滚动条。这似乎是一个沉重的解决方案,但暂时会起作用。当我将它移到Windows Phone 7时,我肯定需要找到更轻的重量。

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" mc:Ignorable="d"
x:Class="SilverlightApplication2.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White" >
    <ScrollViewer x:Name="scrollViewer" Margin="0,0,158,0" VerticalScrollBarVisibility="Disabled" Height="123" VerticalAlignment="Top">
        <Grid x:Name="grid" VerticalAlignment="Top" MaxWidth="169" MaxHeight="145" Height="141" RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <CompositeTransform/>
            </Grid.RenderTransform>
            <Button Content="Button" Margin="25,42,0,60" HorizontalAlignment="Left" Width="71"/>
            <Button Content="Button" Height="76" Margin="25,0,0,-83" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="81"/>
        </Grid>
    </ScrollViewer>
</Grid>

相关问题