Fishman
Fishman

Reputation: 73

WPF create thumbnail by VisualBrush

I have a user control for display thumbnail of a window

UserControl XAML :

<Grid x:Name="containerGrid" Margin="0">
        <Border Background="White" CornerRadius="5">
            <Border.Style>
                <Style>
                    <Style.Triggers>
                        <Trigger Property="Border.IsMouseOver" Value="True">
                            <Setter Property="Border.Effect">
                                <Setter.Value>
                                    <DropShadowEffect BlurRadius="20" Color="White" ShadowDepth="0" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <Border x:Name="containerBorder" CornerRadius="5" BorderThickness="1" BorderBrush="Black">
                <Border.Background>
                    <VisualBrush x:Name="vb" />
                </Border.Background>                
            </Border>
        </Border>
    </Grid>

Once a new window been created, I let above user control display thumbnail of window content by VisualBrush

vb.Visual = (Border)Win.Template.FindName("mainBorder", Win);

Everything seems work fine...

Opened Window enter image description here

Thumbnail

enter image description here

Until the window size changed by user... enter image description here

Thumbnail

enter image description here

My question is how should I do to let thumbnail width and height always fits my user control (200 X 200) no matter how source(window) size changed??

Many thanks if there is any clue.

SOLVED by set Stretch to Fill and ViewBox to window ActualWidth and ActualHeight

<VisualBrush x:Name="vb" Stretch="Fill" ViewboxUnits="Absolute">
                        <VisualBrush.Viewbox>
                            <MultiBinding Converter="{CONV:WidthHeightToRectConverter}">
                                <Binding Path="Win.ActualWidth" />
                                <Binding Path="Win.ActualHeight" />
                            </MultiBinding>
                        </VisualBrush.Viewbox>                        
                    </VisualBrush>

Upvotes: 0

Views: 259

Answers (1)

Andy
Andy

Reputation: 12276

You could try setting stretch on your visualbrush.

<VisualBrush Stretch="Fill"

There are other options on stretch but I think Fill will be the one you want.

Upvotes: 0

Related Questions