簡體   English   中英

畫布與父邊框重疊

[英]Canvas overlaps parent border

我正在努力解決布局問題。 我的用戶控件包含一個邊框,其中一個畫布作為子級。 該畫布包含一個網格,該網格包含2個畫布(1列和2行具有不同的顏色)。

我的問題是網格與他右側的邊框重疊,我不知道為什么。 我試圖將主畫布的ClipToBounds屬性設置為“ True”,但沒有任何效果。

你能幫助我嗎 ?

這是問題所在:

問題

這是代碼:

<Border Name="MainBorder" BorderBrush="Black" BorderThickness="1">
   <Canvas Name="MainCanvas" Height="30" ClipToBounds="True">
      <Grid Width="{Binding ElementName=MainCanvas, Path=ActualWidth}">
          <Grid.RowDefinitions>
              <RowDefinition Height="5" />
              <RowDefinition Height="5" />
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
              <ColumnDefinition />
          </Grid.ColumnDefinitions>

          <Canvas Name="CanvasTop" Grid.Row="1" Grid.Column="0" Background="Beige" />
          <Canvas Name="CanvasBottom" Grid.Row="0" Grid.Column="0" Background="LightGray" />
      </Grid>
   </Canvas>
</Border>

謝謝您的幫助。

我認為這是造成您的Width =“ {Binding ElementName = MainCanvas,Path = ActualWidth}”行的原因。

您可以嘗試使用Horizo​​ntalAlignment =“ Stretch”而不是width屬性。 這將確保它使用整個寬度

問題解決了,在代碼的后面有一個函數以錯誤的方式調整了控件的大小:

public void SetMainCanvasWidth(double size)
{
    Width = Math.Max(2, size); // that line was evil. removed it and it runs
    MainCanvas.Width = Math.Max(2, size);
}

謝謝您的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM