2011-12-09 6 views
0

このような例では、グリッドにボタン全体を赤で塗りつぶしたいとします。グリッドやキャンバスをボタンの内容を埋めるように伸ばすにはどうすればよいですか?

<Button Margin="2"> 
    <Grid x:Name="adGrid" Background="Red">        
     <StackPanel>          
      <StackPanel Orientation="Horizontal"> 
       <TextBlock Text="{Binding ActualWidth, ElementName=adGrid}"></TextBlock> 
       <TextBlock Text="x"></TextBlock> 
       <TextBlock Text="{Binding ActualHeight, ElementName=adGrid}"></TextBlock> 
      </StackPanel> 
     </StackPanel> 
    </Grid> 
</Button> 

私はちょうどこれで終わる:ここでの問題はGrid全体Buttonをカバーしていないことである

enter image description here

答えて

4

。あなたがしたい場合は、全体Buttonredが赤にbuttonbackground色を設定したり、button

いずれかを実行

<Button Margin="2" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> 

または

<Button Margin="2" Background="Red"> 
     ... 
</Button> 
の残りの部分をカバーするために gridを伸ばすのいずれかに
関連する問題