These are chat archives for AvaloniaUI/Avalonia

3rd
Mar 2016
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 15:44
DataTriggerBehavior demonstration, used 100% XAML
also ElementName binding and SolidColorBrush resources
Nikita Tsukanov
@kekekeks
Mar 03 2016 15:51
mono/SkiaSharp#36
Steven Kirk
@grokys
Mar 03 2016 16:53
so looks like they're being pretty good with PRs
@wieslawsoltes added a comment to your issue explaining why things are as they are atm
if there's anything that needs more explanation, let me know and i will add it
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 16:54
reading...
Nikita Tsukanov
@kekekeks
Mar 03 2016 16:54
Well, for now I've got my text measurement improvements merged, let's see how it will be with more complex stuff
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 16:56
@grokys Thanks for explanation, I understand the reason why thing are like this
Steven Kirk
@grokys
Mar 03 2016 17:00
glad that made sense at least!
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:01
yes it was very clear
just I am used to WPF way of things too much
but also I see some benefits of using styles for resource definition
@grokys
    <Window.Styles>
        <Style Selector="TabItem">
            <Style.Resources>
                <SolidColorBrush x:Key="BlackBrush">Black</SolidColorBrush> 
                <SolidColorBrush x:Key="GrayBrush">Gray</SolidColorBrush>
                <SolidColorBrush x:Key="RedBrush">Red</SolidColorBrush>
                <SolidColorBrush x:Key="BlueBrush">Blue</SolidColorBrush>
                <SolidColorBrush x:Key="YellowBrush">Yellow</SolidColorBrush>
                <SolidColorBrush x:Key="PinkBrush">Pink</SolidColorBrush>
            </Style.Resources>
        </Style>
        <Style Selector="TabItem.override">
            <Style.Resources>
                <SolidColorBrush x:Key="GrayBrush">Orange</SolidColorBrush>
            </Style.Resources>
        </Style>
    </Window.Styles>
playing with resources
the GrayBrush from Selector="TabItem.override" is used also in TabItems without Classes="override" specified
is this intended behavior ?
Steven Kirk
@grokys
Mar 03 2016 17:07
yes, if i understand you correctly - the resources are part of the style, and apply to any point down the tree after that style is defined
they can't depend on selectors, as selectors apply to controls, not styles
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:07
full xaml
Steven Kirk
@grokys
Mar 03 2016 17:08
what i think you're wanting to do, and i'd like it too - is conditionally set a resource in a control depending on a selector
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:08
that was my intentation
to control resources using selectors and classes
Steven Kirk
@grokys
Mar 03 2016 17:09
yeah, that would be nice
i'm worried it'd be terrible for memory usage though
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:10
so what happens when I redefine GrayBrush ?
is the last one used
Steven Kirk
@grokys
Mar 03 2016 17:10
yep
same as WPF in that respect
the one closest to the control that's looking for the resource, moving up the tree is used
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:11
In WPF you would get MainWindow.xaml(11,26): error MC3020: The dictionary key 'GrayBrush' is already used. Key attributes are used as keys when inserting objects into a dictionary and must be unique. Line 11 Position 26.
Steven Kirk
@grokys
Mar 03 2016 17:17
that's when inserting two objects with the same key into the same dictionary
you can't do that in perspex either
but in both WPF and Perspex you can have two objects with the same key in different dictionaries
@wieslawsoltes added another comment to the issue, not sure you'll agree with this one
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:21
I agree 100%
maybe we can only have one place for resource definition in Application xaml so this is only parsed once and is static for the rest of application lifecycle
Steven Kirk
@grokys
Mar 03 2016 17:27
perhaps, though i think that may be confusing, and not actually fix any of the problems with resources
because unless there was a different markup extension to search for those resources, the tree would still have to be traversed
and not sure i want to introduce a different markup extension...
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:33
so for now only StyleResource will be available for cosuming resources
Steven Kirk
@grokys
Mar 03 2016 17:33
yeah, i think so. though you should be able to use it everywhere you can use StaticResource in WPF
i was going to say we could expose the application's style resources in Application.Resources
but Application.Styles can (and will) contain many styles, each with their own resources
so i don't think that's feasable after all
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:35
this works :)
    <Window.Styles>
        <Style>
            <Style.Resources>
                <Rectangle x:Key="RectKey" Width="100" Height="100" Fill="Red"/>
            </Style.Resources>
        </Style>
    </Window.Styles>
    <Grid>
        <TabControl>
            <TabItem Header="CallMethodAction">
                <!-- TODO -->
                <ContentControl Content="{StyleResource RectKey}"/>
            </TabItem>
Steven Kirk
@grokys
Mar 03 2016 17:36
yep :)
the name StyleResource doesn't mean "resource for a style" - it means "resource defined in a style"
so it can be used everywhere
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:36
yes this is confusing
Steven Kirk
@grokys
Mar 03 2016 17:36
yeah, i could change the name
none of this stuff is a final decision
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:37
Resource maybe
Steven Kirk
@grokys
Mar 03 2016 17:37
your input really helps
yeah, maybe just Resource
but what if we end up adding Resources like in WPF?
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:37
we have Static already, short and simple
Steven Kirk
@grokys
Mar 03 2016 17:37
yep, and static is much more performant
and could even be cached if necessary to improve perf further
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:38
so when I use StyleResource each time you have to search for this resource ?
Steven Kirk
@grokys
Mar 03 2016 17:38
yep
same in all xaml frameworks with resources
there are ways we could speed it up by maintaining a cache but the problem is that the contents can change for each control
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:40
WPF has notion of static and dynamic resources
Steven Kirk
@grokys
Mar 03 2016 17:40
yeah, they both have to traverse the tree
at the moment StyleResource is more like StaticResource
but i want to allow changing of styles at runtime in future which will make it more like DynamicResource
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:42
is traversing done only during xaml load ?
Steven Kirk
@grokys
Mar 03 2016 17:42
yeah, at the moment
adding resources won't affect already loaded controls
though with the changes i mentioned just now, i hope that can change
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:43
I think loading xaml isn't that slow
Steven Kirk
@grokys
Mar 03 2016 17:43
it is on mobile ;)
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:44
well I'm using Core i7 ;)
with very fast ram
Steven Kirk
@grokys
Mar 03 2016 17:44
there are loads of places i'm worried about perf for the future
i didn't worry about it early on, because i just wanted to get stuff running
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:45
well anything dynamic in xaml may be a killer to perf
Steven Kirk
@grokys
Mar 03 2016 17:46
thing i'm most worried about is styling controls with classes
as every style with a class selector adds an event listener to every control of that class
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:47
I use the classes evrywhere
but you remeber I have tested this
and removed all classes without inpact on perf
Steven Kirk
@grokys
Mar 03 2016 17:47
well it's more memory i'm worrying about
but there are ways to minimize the effect
btw, i've found the leak that you're seeing in Core2D
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:48
wow
Steven Kirk
@grokys
Mar 03 2016 17:48
but haven't worked out what causes it yet
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:48
what is leaking ?
Steven Kirk
@grokys
Mar 03 2016 17:49
event listeners to control classes ;)
or something related to that
btw @danwalmsley i'm sorry i;ve not responded to your problem yet - been busy with work and trying to diagnose this leak
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:50
@grokys Did you see my issues Perspex/Perspex#460 and Perspex/Perspex#461
both are related to work I'm doing with XamlBehaviors
Steven Kirk
@grokys
Mar 03 2016 17:51
ah i'd not seen #461
on this line:
<ia:InvokeCommandAction Command="{Static Editor:Commands.NewCommand}" CommandParameter="{Binding}"/>
what should that be binding to?
as InvokeCommandAction isn't a control and so doesn't have a DataContext as the error is saying
Jeremy Koritzinsky
@jkoritzinsky
Mar 03 2016 17:52
With the memory leaks, you should look at implementing weak events (delegates that hold weak references) as a possible fix.
Steven Kirk
@grokys
Mar 03 2016 17:53
@jkoritzinsky yeah, though that shouldn't be necessary in this instance
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:53
to DataContext of attached object
Steven Kirk
@grokys
Mar 03 2016 17:53
ok, i'll need to support that scenario
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:54
I can workaround for now using <ia:InvokeCommandAction Command="{Static Editor:Commands.NewCommand}" CommandParameter="{Binding #newProject.DataContext}"/>
Steven Kirk
@grokys
Mar 03 2016 17:54
@jkoritzinsky the lifetime should be being controlled, but there's a bug somewhere that's causing a reference to be held
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:54
more annoying is Perspex/Perspex#460
as I cannot use workaround from issue #461
the #460 and #461 would enable me to use event to command behaviors inside data templates, and that is big thing
Steven Kirk
@grokys
Mar 03 2016 17:59
i'll try to fix that then
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 17:59
would be greatly appreciated
I have branch https://github.com/Core2D/Core2D/tree/XamlBehaviorsIssues where you can test this issues, just look for DashboardControl.xaml
Steven Kirk
@grokys
Mar 03 2016 18:10
ah.. i see what the problem is
the Name is applied to a listbox item template
so it'll try to create multiple items with the same name
does that work in WPF?
i can't see how it could
Nikita Tsukanov
@kekekeks
Mar 03 2016 18:22
Guys, I'll be talking about xplat ui frameworks on a conference in april, so I need "Why Perspex is awesome" list. For now my list is:
  • Full XAML support with bindings, control templates and list item templates
  • Fully customizable thanks to custom rendering
  • GetObservable + INotifyPropertyChanged from PerspexProperty
  • Task support in bindings
  • ! negation in bindings
  • Unified DrawingContext for all platforms
  • You can write ColumnDefinition="10,,,200"
  • ListBox.SeletedItems is bindable
  • CSS-like style selectors
  • Popups and tooltips inherit DataContext
  • Our ArcTo is capable of accurately drawing comet orbits
Darnell Williams
@Seeker1437
Mar 03 2016 18:27
:D
Binding to tasks
Nikita Tsukanov
@kekekeks
Mar 03 2016 18:28
Yep, you can actually bind to a property that returns Task<string>
Really convenient for stuff that is loaded asynchronously
Steven Kirk
@grokys
Mar 03 2016 18:28
coool! which conference?
Darnell Williams
@Seeker1437
Mar 03 2016 18:28
Noce! I didnt know that... Makes something I was trying possible
Nikita Tsukanov
@kekekeks
Mar 03 2016 18:29
CLRium. It's held in several russian cities and you probably never heard of it
Steven Kirk
@grokys
Mar 03 2016 18:29
i hope there will be a video with translations ;)
Darnell Williams
@Seeker1437
Mar 03 2016 18:30
Hehe
Steven Kirk
@grokys
Mar 03 2016 18:30
i think you've got most of the good points there
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 18:44

Guys, I'll be talking about xplat ui frameworks on a conference in april, so I need "Why Perspex is awesome" list. For now my list is:

@kekekeks You can mention XamlBehaviors if you would like, I have got them working

does that work in WPF?

@grokys It works, just tested

        <ListBox x:Name="recentProjects" 
                 ItemsSource="{Binding Path=RecentProjects}" 
                 SelectedItem="{Binding Path=CurrentRecentProject, Mode=TwoWay}"
                 Grid.Column="3" Grid.Row="3" Grid.ColumnSpan="1" Grid.RowSpan="5">
            <ListBox.Resources>
                <DataTemplate DataType="{x:Type Recent:RecentFile}">
                    <TextBlock x:Name="text" Text="{Binding Path=Name}" Style="{StaticResource RecentsTextBlockStyleKey}" ToolTip="{Binding Path=Path}"/>
                </DataTemplate>
            </ListBox.Resources>
        </ListBox>
Steven Kirk
@grokys
Mar 03 2016 18:46
wow... i have no idea how that works. do all the TextBlocks have the same name?
i guess the root control created by the DataTemplate must be a name scope
Steven Kirk
@grokys
Mar 03 2016 19:30
balls.. actually i'd not found your leak @wieslawsoltes
Steven Kirk
@grokys
Mar 03 2016 20:23
@danwalmsley your problem with StyleResource not working on Window should now be fixed.
Steven Kirk
@grokys
Mar 03 2016 20:50
ok @wieslawsoltes, #461 should be fixed
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:16

i guess the root control created by the DataTemplate must be a name scope

@grokys I think this is true, DataTemplate should be a name scope, I would not access any control outside the DataTemplate

Steven Kirk
@grokys
Mar 03 2016 21:17
yep, just verified it with WPF - implementing now
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:17
great
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:24
@grokys #461 still is throwing same exception
        <Button Name="newProject" Content="New Project" Classes="project" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="1" Grid.RowSpan="1">
            <i:Interaction.Behaviors>
                <ia:EventTriggerBehavior EventName="Click" SourceObject="{Binding #newProject}">
                    <ia:InvokeCommandAction Command="{Static Editor:Commands.NewCommand}" CommandParameter="{Binding}"/>
                </ia:EventTriggerBehavior>
            </i:Interaction.Behaviors>
        </Button>
Steven Kirk
@grokys
Mar 03 2016 21:24
:(
ok, i'll take a look when i've finished the datatemplate namescope stuff
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:25
ok
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:33
@grokys Oh the CI failed for #461 fix
Steven Kirk
@grokys
Mar 03 2016 21:34
ah, really?
ok
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:34
maybe its false alarm
Steven Kirk
@grokys
Mar 03 2016 21:34
yeah, looks like a network error. just committed the datatemplate namescope fix, so lets see what happens
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:34
waiting for CI to finish
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:41
#461 is fixed :)
@grokys #460 is fixed
now this works
        <ListBox Items="{Binding Path=RecentProjects}" SelectedItem="{Binding Path=CurrentRecentProject, Mode=TwoWay}" Classes="recents" Grid.Column="3" Grid.Row="3" Grid.ColumnSpan="1" Grid.RowSpan="5">
            <ListBox.DataTemplates>
                <DataTemplate DataType="Recent:RecentFile">
                    <Grid Name="grid" ColumnDefinitions="*,Auto">
                        <i:Interaction.Behaviors>
                            <ia:EventTriggerBehavior EventName="DoubleTapped" SourceObject="{Binding #grid}">
                                <ia:InvokeCommandAction Command="{Static Editor:Commands.OpenCommand}" CommandParameter="{Binding Path}"/>
                            </ia:EventTriggerBehavior>
                        </i:Interaction.Behaviors>
                        <TextBlock Text="{Binding Path=Name}" Classes="recents" Grid.Column="0" ToolTip.Tip="{Binding Path=Path}"/>
                        <Button Content="open" Classes="recent" Grid.Column="1" Command="{Static Editor:Commands.OpenCommand}" CommandParameter="{Binding Path=Path}"/>
                    </Grid>
                </DataTemplate>
            </ListBox.DataTemplates>
        </ListBox>
Steven Kirk
@grokys
Mar 03 2016 21:43
whoo! :)
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:45
i think all behaviors related to Perspex should now work
did not test CallMethodAction but it uses same mechanism as other tested ones
Steven Kirk
@grokys
Mar 03 2016 21:46
it would be really nice to be able to do the above with a markup extension
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:47
how would that look like
Steven Kirk
@grokys
Mar 03 2016 21:48
not sure, something like <Grid DoubleTapped="{EventCommand {Static Editor:Commands.OpenCommand}}"> maybe?
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:48
binding to events
Steven Kirk
@grokys
Mar 03 2016 21:48
and maybe <Grid DoubleTapped="{EventCommand OpenCommand}"> would bind to DataContext.OpenCommand?
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:49
I use static class for my commands
Steven Kirk
@grokys
Mar 03 2016 21:49
something similar was discussed here
SuperJMN/OmniXAML#10
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:50
well this would be great
the power of behaviors is in combining them together
                    <Rectangle Name="DataTriggerRectangle" Grid.Row="0" Fill="{StyleResource BlueBrush}" Stroke="{StyleResource GrayBrush}" StrokeThickness="5">
                        <i:Interaction.Behaviors>
                            <ia:DataTriggerBehavior Binding="{Binding #slider.Value}" ComparisonCondition="GreaterThan" Value="50">
                                <ia:ChangePropertyAction TargetObject="{Binding #DataTriggerRectangle}" PropertyName="Fill" Value="{StyleResource YellowBrush}"/>
                            </ia:DataTriggerBehavior>
                            <ia:DataTriggerBehavior Binding="{Binding #slider.Value}" ComparisonCondition="LessThanOrEqual" Value="50">
                                <ia:ChangePropertyAction TargetObject="{Binding #DataTriggerRectangle}" PropertyName="Fill" Value="{StyleResource BlueBrush}"/>
                            </ia:DataTriggerBehavior>
                        </i:Interaction.Behaviors>
                    </Rectangle>
                    <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <TextBlock Text="{Binding #slider.Value}" VerticalAlignment="Center" Width="50" Foreground="{StyleResource GrayBrush}"/>
                        <Slider Name="slider" Width="150" IsSnapToTickEnabled="True" TickFrequency="1"/>
                    </StackPanel>
Steven Kirk
@grokys
Mar 03 2016 21:51
ooh yeah nice
the only thing i don't like about behaviors is that they're soooooooo verbose
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:52
well
I tried to do this in code before xaml was working in Perspex
this was a lot of code, like tons
well using behaviors not event handlers
well behaviors are really useful inside DataTemplates
Steven Kirk
@grokys
Mar 03 2016 21:53
yeah, i'm not sure code is much better here
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:53
when using code behind is really hard
Steven Kirk
@grokys
Mar 03 2016 21:53
yeah
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:54
does Perspex have nagigation support
Steven Kirk
@grokys
Mar 03 2016 21:55
nope, nothing as high-level as that yet
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:57
anyway I'm very happy to have Behaviors working, this make many things in my app simpler to implement
Steven Kirk
@grokys
Mar 03 2016 21:57
yep, it's really good to have them!
they're really useful
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 21:58
I always was reluctant to use them in WPF as you have pain on managing dependencies from Blend
Steven Kirk
@grokys
Mar 03 2016 22:15
what do you think could be leaking?
Wiesław Šoltés
@wieslawsoltes
Mar 03 2016 22:16
is see like 150000 of them when selected object changes and new DataTemplate is loaded
look like evry control and primitive in DataTemplate tree gets one CompositeDisposable
like
CompositeDisposable [Dependent Handle, Perspex.Controls.Primitives.TabStripItem <0xCCB6AB8>] +1 1
Stano Turza
@Sorien
Mar 03 2016 22:21
hi, just looking to docs and as css guy Button /template/ Border#outline looks really weird maybe something like Button::template Border#outline or Button|template Border#outline could looks better :)
Stano Turza
@Sorien
Mar 03 2016 22:38
or @Button Border#outline $Button Border#outline
Steven Kirk
@grokys
Mar 03 2016 23:07
well it was actually based on css: http://robdodson.me/shadow-dom-css-cheat-sheet/#deep
but the syntax has changed to >>>
Steven Kirk
@grokys
Mar 03 2016 23:16
@wieslawsoltes thing is, CompositeDisposable is used everywhere internally in Rx so it doesn't really tell us much
are you sure it's the one that's created there that's leaking?
i don't see how it could be tbh
Darnell Williams
@Seeker1437
Mar 03 2016 23:37
/!\ Warning: WebServices down. Logging and bot disabled. [Connection Refused]
Darnell Williams
@Seeker1437
Mar 03 2016 23:43
oh sorry
bug in the bot I never fixed...