开发者

Scale a Visual Brush Background WPF

开发者 https://www.devze.com 2022-12-24 16:39 出处:网络
I have a Item called MiniMap in my xaml. I have set the background of it to a visual brush representting a canvas Item. Now, I want to scale the background to a ratio 0.7 . How can I do it?

I have a Item called MiniMap in my xaml. I have set the background of it to a visual brush representting a canvas Item. Now, I want to scale the background to a ratio 0.7 . How can I do it? Thanks in advance

<local:MiniMap Width="201" Height="134" x:Name="MiniMapItem" MinHeight="100" MinWidth="100" Opacity="1" SnapsToDevicePixels="True" Margin="0,0,20,20" VerticalAlignment="Bottom" 开发者_如何转开发HorizontalAlignment="Right">
                    <local:MiniMap.Background>
                        <VisualBrush Visual="{Binding ElementName=viewport}" Stretch="None" TileMode="None" AlignmentX="Left" AlignmentY="Top" />
                    </local:MiniMap.Background>
                </local:MiniMap>


Try this:

<VisualBrush Visual="{Binding ElementName=viewport}" Stretch="None" TileMode="None" AlignmentX="Left" AlignmentY="Top">
   <VisualBrush.Transform>
      <ScaleTransform ScaleX="0.7" ScaleY="0.7" />
   </VisualBrush.Transform>
</VisualBrush>

You may need to play with the CenterX and CenterY properties to get it to look right. Usually you'll want them to be set to the middle point of what you're scaling.


The VisualBrush element has the property Viewbox, which can be used to scale the background.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号