代码之家  ›  专栏  ›  技术社区  ›  TalkingCode

如何防止可视画笔拉伸其内容

wpf
  •  7
  • TalkingCode  · 技术社区  · 15 年前

    在我的项目中,我想在自定义控件的一侧显示一个小徽标。因为我没有画布,所以我想用一个视觉刷把商标放在背景上是个好主意。

    <VisualBrush>
        <VisualBrush.Visual>
            <Rectangle Width="200" Height="200" Fill="Red" />
        </VisualBrush.Visual>                
    </VisualBrush>
    

    但我现在使用的矩形不是200x200。它需要完整的可用空间。这不是我想要的。我还尝试了一个viewbox并设置了Stretch属性,但是结果是一样的,因为最后我不需要一个简单的矩形,而是需要一个包含许多路径对象作为子对象的画布。一个视图框只支持一个子项。

    有什么办法解决这个问题吗?

    3 回复  |  直到 6 年前
        1
  •  10
  •   Mark Heath    8 年前

    TileMode Stretch AlignmentX AlignmentY VisualBrush

    <VisualBrush TileMode="None" Stretch="None" AlignmentX="Left" AlignmentY="Top">
        <VisualBrush.Visual>
            <Rectangle Height="200" Width="200" Fill="Red"></Rectangle> 
        </VisualBrush.Visual>
    </VisualBrush>
    
        2
  •  0
  •   Firoz    15 年前

      <VisualBrush x:Key="myVisual">
            <VisualBrush.Visual>
                <Grid>
                    <Rectangle Height="200" Width="200" Fill="Red" HorizontalAlignment="Right"  VerticalAlignment="Top" ></Rectangle> 
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>
    
        3
  •  0
  •   nikotromus    6 年前

    Stretch="Uniform"