tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

VisualBrush is doesn't work

26 Aug 2019, 13:59

Hi,

VisualBrush is already supported, right?
https://www.noesisengine.com/docs/Gui.C ... Brush.html
I confirmed to exist VisualBrush.h/.cpp files.
The following code displays correctly in WPF, but noesis is not.
<Grid>
    <Grid.Background>
        <VisualBrush>
            <VisualBrush.Visual>
                <Grid>
                    <Label Background="Red">Red</Label>
                </Grid>
            </VisualBrush.Visual>
        </VisualBrush>
    </Grid.Background>
</Grid>
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: VisualBrush is doesn't work

28 Aug 2019, 21:28

Current implementation of VisualBrush in Noesis only allows to render visuals that are already in the UI tree (to generate duplicates, reflections, ...):
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
            <GradientStop Color="#FF393C3E" Offset="0.2"/>
            <GradientStop Color="#FF25282A" Offset="0.21"/>
            <GradientStop Color="#FF485058" Offset="1"/>
        </LinearGradientBrush>
    </Grid.Background>
    <Viewbox Margin="100">
        <Grid VerticalAlignment="Center" Margin="0,20,0,0">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid x:Name="Src" Width="500" Background="Transparent">
                <Button Margin="16,0" Width="120" Padding="2,1" Content="Button 1" HorizontalAlignment="Center"/>
                <Ellipse Fill="Red" Width="60" Height="60" Margin="100,0" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
            </Grid>
            <Rectangle Height="100" Grid.Row="1">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleY="0.5"/>
                        <SkewTransform AngleX="-30"/>
                    </TransformGroup>
                </Rectangle.RenderTransform>
                <Rectangle.Fill>
                    <VisualBrush Visual="{Binding ElementName=Src}">
                        <VisualBrush.RelativeTransform>
                            <ScaleTransform ScaleY="-1" CenterY="0.5"/>
                        </VisualBrush.RelativeTransform>
                    </VisualBrush>
                </Rectangle.Fill>
                <Rectangle.OpacityMask>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Color="#40FFFFFF" Offset="0"/>
                        <GradientStop Color="#00FFFFFF" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.OpacityMask>
            </Rectangle>
        </Grid>
    </Viewbox>
</Grid>
What do you want to achieve?
 
tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

Re: VisualBrush is doesn't work

29 Aug 2019, 08:21

Thank you for your reply.
What do you want to achieve?
I try to reuse icon images of SVG(XAML) as resources.

It define VisualBrush of icon image as resource.
<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <VisualBrush x:Key="SvgImage_1">
        <VisualBrush.Visual>
            <Grid> 
                <!-- SVG icon image -->
            </Grid>
        </VisualBrush.Visual>
    </VisualBrush>
</ResourceDictionary>
The VisualBrush is use with other XAML.
<Button Background="{Binding SvgImageName, Converter={StaticResource ConverterSvgImageToBrush}}"/>
ConverterSvgImageToBrush converts to VisualBrush from (string)SvgImageName by ResourceDictionary.
In Blend(c#), it converts to ImageBrush of PNG for not breaking designer view of Blend.

Icon images XAML is created from SVG files when build vcxproj. So, user doesn't know resource name(x:key) until that time. Therefore, it cannot use "{StaticResource SvgImage_1}".
It doesn't have to be a Brush, but I suggested this as a way to reuse SVG image resources without breaking Blend's designer.
Please let me know if there is any other way.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: VisualBrush is doesn't work

29 Aug 2019, 10:35

Are these icon images formed with several paths and strokes with different brushes and pens?

If icons can be represented as a single geometry with a single brush/pen you can probably use Geometry resources instead and use them to specify the Data property of a Path shape (using a binding and your converter to determine the final resource name).

If icons contain different geometries then you can define them as a ControlTemplate to reuse them as controls.

I talked about these options in this post: viewtopic.php?f=3&t=814&p=4480&hilit=co ... icon#p4446
 
tkawa
Topic Author
Posts: 18
Joined: 07 Nov 2018, 05:34

Re: VisualBrush is doesn't work

03 Sep 2019, 06:06

I decided to solve it using ControlTemplate.
Thank you very much!!

Who is online

Users browsing this forum: Google [Bot] and 12 guests