2011-07-27 7 views
2

私はSilverlightを使用しています。グリッドコントロールをコンテナコントロールとして機能させることは可能ですか?

私がしようとしているのは、子コントロールを含む枠線付きのコンテナを作成することです。子コントロールは、グリッドコントロールの範囲外にあるときは表示しないでください。

これは可能ですか?私はパスからクリップを作成できますが、これは唯一の方法です。

私はスクロールコンテナを使っていましたが、ややこしいものでした。

これはxamlです。私が期待しているのは、アプリケーションがランニング中に2番目のボタンが表示されないことです。

<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> 
+0

ない、あなたが求めているのかわからこれを移動するとき、私は間違いなく軽く何か重みを見つける必要がありますTranslateTransformのようなものを使っていました。 –

+0

私を混乱させるものは、含まれているグリッドの境界は参照点としての動作以外は何もしないようです。含まれているグリッドはルートと同じサイズ(実質的に)のようです –

+0

私はまだあなたの質問を理解できませんが、あなたの最後のコメントに答えるために、グリッドは常にコンテナのサイズを取るので、含まれているグリッドはまったく同じになりますLayoutRootグリッドとしてのサイズ。 –

答えて

0

私は回避策を見つけましたが、別の解決方法を使用したいと考えています。私はスクロールバーを使い、スクロールバーを隠しました。これは重い解決策のようですが、当面はうまくいくでしょう。通常、子要素はあなたしない限り、Grid要素の外に見えない - 私は、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> 

2

使用UIElement.ClipToBounds

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

<Grid ClipToBounds="True"> 

    ... 

</Grid> 
+0

私はそれが 'Canvas'コントロールでのみ動作すると信じています – Rachel

+0

いいえ、それもグリッドで動作します。上記のコーチデビッドのXamlと試してみてください。 –

+0

ClipToBoundsという名前のプロパティは存在しません。クリップがあります。 –

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> 

あなたは何か他のことを求めている。しかし何?

+0

私はあなたの権利を考えていますが、これはルートレイアウトにのみ適用されるようです。 –

関連する問題