These are chat archives for AvaloniaUI/Avalonia

5th
Mar 2016
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 07:48 UTC
@grokys Hi, please check the Perspex/Perspex#463
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 09:06 UTC
@grokys And also please check my pull request #464, this should enable binding to Canvas properties, currently I get exception when trying to bind
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 09:17 UTC
But I still can't get working fully. When I change bound property and raise INPC the e.g. Canvas.Left attached property is not affected
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 09:30 UTC
Ok, I have managed to make it working by observing property changes and calling InvalidateArrange manually on Parent.
Steven Kirk
@grokys
Mar 05 2016 10:44 UTC
hmm, that shouldn't be necessary because of this line: https://github.com/Perspex/Perspex/blob/master/src/Perspex.Controls/Canvas.cs#L49
which invalidates the arrange of the control when its position changes
one idea: it might just not be getting redrawn. after you change the position and nothing changes onscreen, does resizing the window cause it to suddenly snap into place?
i will take a look myself but at the moment, i am soooo close to finding your leak, i want to concentrate on that!
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:02 UTC
@grokys
I reimplemented basic Grid logic
and it basically works
but I cannot load DevTools
because for one of the grids inside that window you create 2 columns without rows and pass infinite size as measure, but actually it creates 1 star row, which cannot be measure because height is infinite
that leads to expection during measure pass of underlying controls
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 11:04 UTC

one idea: it might just not be getting redrawn. after you change the position and nothing changes onscreen, does resizing the window cause it to suddenly snap into place?

@grokys Resizing window does help, now than what change is necessary to make it work ?

i will take a look myself but at the moment, i am soooo close to finding your leak, i want to concentrate on that!

Great!

Steven Kirk
@grokys
Mar 05 2016 11:05 UTC
@wieslawsoltes for the moment add this line to the static ctor: AffectsRender(LeftProperty, TopProperty, RightProperty, BottomProperty);
you shouldn't need to do that, but invalidating arrange isn't correctly invalidating render atm
@QuantumDeveloper could you point me to the code in DevTools that's causing the problem?
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:08 UTC
unfortunately I dont understand where actually all of controls creating for DevTools, but I think this is happening inside tabcontol with Visual tree and maybe Logical tree tab too
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 11:08 UTC
@grokys AffectsRender does not work
Steven Kirk
@grokys
Mar 05 2016 11:08 UTC
hmm, strange
@QuantumDeveloper as far as i can see the only grid in devtools is created with 3 columns, not two
and rows are also created
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:09 UTC
there is at least 3 grids in devtools
can you point me to the actual code for devtools?
and it uses this GridRepeater behavior to create the rows
(i know that's not the best way to do it, i was an experiment a long time ago ;) )
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:13 UTC
strange
how it could work in old implementation?
aha
that grid is inside stack panel
do you know something about that?
Steven Kirk
@grokys
Mar 05 2016 11:28 UTC
it's not inside a StackPanel, it's inside a ScrollViewer
you can see that two lines above where it's created
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:29 UTC
@grokys last measure pass before fail says its inside stack panel
Visual Parent = Perspex.Controls.StackPanel
Logical Parent = Perspex.Controls.StackPanel
Steven Kirk
@grokys
Mar 05 2016 11:30 UTC
ok, i suspect that it's not that grid that you're looking at then
it must be a grid inside a control template
what is the TemplatedParent property?
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:31 UTC
1 minute
Templated Parent = Perspex.Controls.TreeViewItem
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:38 UTC
issue is that while row actually a star we receive infinite size, so star row will be infinite here, because we didnt provide real height for calculations
Steven Kirk
@grokys
Mar 05 2016 11:39 UTC
ok, but infinite height for measure is a valid value
it means "take as much space as you want"
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:39 UTC
yeah
but
according to MS Grid logic we split grid cells to groups
and calculate them one by one
//  Grid classifies cells into four groups depending on
                  //  the column / row type a cell belongs to (number corresponds to
                  //  group number):
                  //
                  //                   Px      Auto     Star
                  //               +--------+--------+--------+
                  //               |        |        |        |
                  //            Px |    1   |    1   |    3   |
                  //               |        |        |        |
                  //               +--------+--------+--------+
                  //               |        |        |        |
                  //          Auto |    1   |    1   |    3   |
                  //               |        |        |        |
                  //               +--------+--------+--------+
                  //               |        |        |        |
                  //          Star |    4   |    2   |    4   |
                  //               |        |        |        |
                  //               +--------+--------+--------+
here is grid for grid)
for current case we have only group 4 and 2
and as far as we dont have 1 group, we dont have basic value for height/width calculations
Steven Kirk
@grokys
Mar 05 2016 11:43 UTC
ok... but Grid handles this type of situation, right?
i don't know the answer, but you should try to work out what the existing Grid/WPF Grid does in this situation
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:44 UTC
yeah, will try to resolve that situation somehow
Steven Kirk
@grokys
Mar 05 2016 11:45 UTC
i would advise setting up unit tests that can work both in WPF and in Perspex
so you can use the same code in both frameworks
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 11:45 UTC
i also thinking about that
Steven Kirk
@grokys
Mar 05 2016 12:57 UTC
wow, nice one! that looks really powerful
is everything to do with binding and behaviors working now?
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 12:57 UTC
yes
the UI is defined 100% in xaml
no code behind
actually I have changed samples from original to use more ViewModel
Darnell Williams
@Seeker1437
Mar 05 2016 12:58 UTC
:OOO
whoa :D
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 12:59 UTC
so you can have your MVVM pure :smile:
the whole UI is 160 lines of XAML, view model is 60 lines
Darnell Williams
@Seeker1437
Mar 05 2016 13:04 UTC
the whoooole ui?
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 13:04 UTC
yes
Darnell Williams
@Seeker1437
Mar 05 2016 13:04 UTC
Perspex compatible?
yes
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 13:04 UTC
yes 100% Perspex goodness
Darnell Williams
@Seeker1437
Mar 05 2016 13:05 UTC
WOW I LIKE THIS!
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 13:05 UTC
this is port of UWP version to Perspex
you can play with this using NuGet package https://www.myget.org/F/xamlbehaviors-nightly/api/v2
Darnell Williams
@Seeker1437
Mar 05 2016 13:07 UTC
I will!
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 13:08 UTC
Darnell Williams
@Seeker1437
Mar 05 2016 13:08 UTC
I'm surious if this would allow me to accomplish transitions too
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 13:10 UTC
you can control events, change properties etc.
invoke commands, methods
Darnell Williams
@Seeker1437
Mar 05 2016 13:15 UTC
epic :D
Oh okay for a quick question, I think this was mentioned a long time ago, but to achieve the same thing as WPF's Visibility.Hidden, I just have to set IsVisible to false as well as IsHitTestVisibile correct?
Darnell Williams
@Seeker1437
Mar 05 2016 13:35 UTC
Also why do I have the feelings PropertyTransition does what my transition class + transitionpresenter can do :O
Steven Kirk
@grokys
Mar 05 2016 13:42 UTC
@Seeker1437 yes that's right
PropertyTransition, as its name suggests, is used to transition properties from their old value to their new value
so if you have Foo = 1 and then set Foo = 100 with a linear transition of 1, it will ramp up from 1 to 100
Steven Kirk
@grokys
Mar 05 2016 13:52 UTC
@wieslawsoltes well i fixed one leak that was showing up in Core2D but it seems there are more ;)
Darnell Williams
@Seeker1437
Mar 05 2016 13:53 UTC

@grokys Ah gottcha, quick question for you then:

Animate.Property(transitionPresenter, ContentPresenter.ContentProperty, oldContent, newContent,
    new LinearDoubleEasing(), this.Duration);
Animate.Property(transitionPresenter, ContentPresenter.ContentProperty, newContent, oldContent,
    new LinearDoubleEasing(), this.Duration);

what this is supposed to do is fade out the old content and fade in the new content at the same time, is this correct? (not in a position where I can test yet)

Steven Kirk
@grokys
Mar 05 2016 13:53 UTC
hmm, you can't really animate a Content property as its not a number
LinearDoubleEasing - that means it's trying to animate a double property
ContentPresenter.Content is an object
so i don't really see how you expect it to fade out by animating the content!
Darnell Williams
@Seeker1437
Mar 05 2016 13:55 UTC
Oh my brain oops
I needed to use Visual.OpacityProperty
Steven Kirk
@grokys
Mar 05 2016 13:55 UTC
ContentPresenter doesn't support transitions yet
yeah, but you'll be fading out the ContentPresenter itself
Darnell Williams
@Seeker1437
Mar 05 2016 13:56 UTC
right
Steven Kirk
@grokys
Mar 05 2016 13:56 UTC
if you're wanting to fade between items, try using Carousel as that has support for transitions
it's an ItemsControl so you add your pages to its Items collection
then set Transition to a CrossFade object
Darnell Williams
@Seeker1437
Mar 05 2016 13:57 UTC
Okay make sense! and that take away some of the ugly logic in the WPF version
Steven Kirk
@grokys
Mar 05 2016 13:57 UTC
then switch between them using SelectedItem or SelectedIndex
i do want to add transition support to ContentControl though
Darnell Williams
@Seeker1437
Mar 05 2016 13:59 UTC
my solutions makes use of doubleanimation for it
this is an old look
danwalmsley
@danwalmsley
Mar 05 2016 14:07 UTC
Is that Perspex or WPF?
Steven Kirk
@grokys
Mar 05 2016 14:16 UTC
looks like WPF with MahApps to me
Darnell Williams
@Seeker1437
Mar 05 2016 14:19 UTC
WPF with MahApps yes
But this basiclaly is animating the COntentPresenter itself
@danwalmsley ;D working on some styles :D @wieslawsoltes 's behaviors will make some things very easy and fun
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 14:24 UTC

@wieslawsoltes well i fixed one leak that was showing up in Core2D but it seems there are more ;)

That is great news! Hope you can find them all :)

Darnell Williams
@Seeker1437
Mar 05 2016 15:25 UTC
@grokys thanks I took your advise and will be using Carousel
Darnell Williams
@Seeker1437
Mar 05 2016 15:39 UTC
How likely are we to have a passwordbox?
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 15:49 UTC
just playing with behaviors
    public class SelectListBoxItemOnPointerMovedBehavior : Behavior<Control>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.PointerMoved += PointerMoved;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.PointerMoved -= PointerMoved;
        }

        private void PointerMoved(object sender, PointerEventArgs args)
        {
            var listBoxItem = AssociatedObject.Parent as ListBoxItem;
            if (listBoxItem != null)
            {
                listBoxItem.IsSelected = true;
                listBoxItem.Focus();
            }
        }
    }
        <ListBox Items="{Binding RecentProjects}" SelectedItem="{Binding 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">
                        <i:Interaction.Behaviors>
                            <local:SelectListBoxItemOnPointerMovedBehavior/>
                            <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 Name}" Classes="recents" Grid.Column="0" ToolTip.Tip="{Binding Path}"/>
                    </Grid>
                </DataTemplate>
            </ListBox.DataTemplates>
        </ListBox>
Darnell Williams
@Seeker1437
Mar 05 2016 16:22 UTC
Nice :smile:
Steven Kirk
@grokys
Mar 05 2016 16:32 UTC
:D
@wieslawsoltes i've just commited some fixes for leaks to master - they should reduce the leaks by quite a bit, but some remain
Steven Kirk
@grokys
Mar 05 2016 16:54 UTC
@wieslawsoltes looking further, i think the remaining leaks may be caused by Core2D - though i'm not positive
i drew a rectangle and an ellipse and switched selection between them repeatedly
dotMemory is reporting that XRectangle and XEllipse are keeping TextBoxes alive through PropertyChanged subscriptions
does that sound possible?
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 16:55 UTC
no
strange
how would my object get hold of UI elements
Steven Kirk
@grokys
Mar 05 2016 16:56 UTC
not sure! i couldn't work that out by looking at the code.
they seem to be INotifyPropertyChanged subscriptions rather than PerspexObject.Property changed subscriptions too
its used evrywhere
and this is bound to UI
Steven Kirk
@grokys
Mar 05 2016 16:59 UTC
i'll keep looking to try and work out what's happening
i suspect it may be two-way bindings
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:00 UTC
I would also suspect that, maybe the INPC subsciption get hold of Core2D objects
Steven Kirk
@grokys
Mar 05 2016 17:02 UTC
yeah, i need to make bindings use weak property listeners
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:12 UTC
@grokys I think TextBox is leaking
try this in Core2D EllipseControl.xaml and than draw 2 ellipse and hove over them
<UserControl xmlns="https://github.com/perspex">
    <TextBox Text="Text" Classes="left"/>
    <!--<TextBlock Text="Text" Classes="left"/>-->
</UserControl>
first try only TextBox inside UserControl
than try only TextBlock inside UserControl
when I try using only TextBlock memory does not go up
Steven Kirk
@grokys
Mar 05 2016 17:13 UTC
This message was deleted
ok, let me try
when you say "hover over them" what do you mean? don't i need to select them with the select tool?
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:16 UTC
no just move mouse over ellipses
this updates selected item
Steven Kirk
@grokys
Mar 05 2016 17:17 UTC
ah! i've been clicking all along ;)
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:17 UTC
oh but after drawing switch to select tool
to enable hover
Steven Kirk
@grokys
Mar 05 2016 17:18 UTC
hmm, it seems that memory does go up even with TextBlocks - just slowly
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:19 UTC
well TextBox is more complex control I guess
Steven Kirk
@grokys
Mar 05 2016 17:19 UTC
yeah
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:19 UTC
and ellipse control has a lot of TextBoxs and TextBlocks inside
Steven Kirk
@grokys
Mar 05 2016 17:19 UTC
but there are no bindings there, which suggests that it's not due to binding
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:20 UTC
well with binding this can be even worse or not hard to tell
maybe its something related to DataContext
even without bindings explicitly set the controls have DataContext set as this is inside DataTemplate ?
Steven Kirk
@grokys
Mar 05 2016 17:23 UTC
hmm
that wouldn't cause the TextBlocks to be kept alive though - there needs to be a reference the other way
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:24 UTC
maybe DataTemplate has reference
Steven Kirk
@grokys
Mar 05 2016 17:25 UTC
ok, the TextBlocks are being collected
        public TextBlock()
        {
            Observable.Merge(
                this.GetObservable(TextProperty).Select(_ => Unit.Default),
                this.GetObservable(TextAlignmentProperty).Select(_ => Unit.Default),
                this.GetObservable(FontSizeProperty).Select(_ => Unit.Default),
                this.GetObservable(FontStyleProperty).Select(_ => Unit.Default),
                this.GetObservable(FontWeightProperty).Select(_=>Unit.Default))
                .Subscribe(_ =>
                {
                    InvalidateFormattedText();
                });

            GC.Collect();

            var alive = s_debug.Select(x =>
            {
                TextBlock result;
                x.TryGetTarget(out result);
                return result;
            }).Where(x => x != null).ToList();

            System.Diagnostics.Debug.WriteLine(alive.Count);

            s_debug.Add(new WeakReference<TextBlock>(this));
        }
i added that to TextBlocks ctor
i reset the count before switch between the two ellipses
and the count remains stable
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:27 UTC
TextBlock does not have xaml template
Steven Kirk
@grokys
Mar 05 2016 17:27 UTC
(for some reason the count is 2 rather than 1 though)
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:27 UTC
the TextBox does
Steven Kirk
@grokys
Mar 05 2016 17:27 UTC
yeah
i was just trying to see what was causing the memory usage to go up with TextBlock
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:28 UTC
and it does have a lot inside template
Steven Kirk
@grokys
Mar 05 2016 17:28 UTC
i will try the same on TextBox
same result there - so the TextBoxs themselves are getting collected
Steven Kirk
@grokys
Mar 05 2016 17:36 UTC
hmm, according to dotMemory the memory usage isn't actually going up there - even with TextBoxs
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:38 UTC
it does go up in VS Diagnostic Tools
Steven Kirk
@grokys
Mar 05 2016 17:38 UTC
yeah, strange
blob
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:40 UTC
the total goes up
Steven Kirk
@grokys
Mar 05 2016 17:42 UTC
and then down again on the 3rd snapshot
look at the difference between the first 2 snapshots, the increase seems to be due to DropDown
which i don't understand
but that rise only happened once, even when switching between the 2 ellipses many many times, so i don't think that's the problem
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:45 UTC
very stange
maybe managed part does not leak
Steven Kirk
@grokys
Mar 05 2016 17:46 UTC
not sure
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:46 UTC
did you try profile unmanaged only memory ?
Steven Kirk
@grokys
Mar 05 2016 17:46 UTC
dotMemory can't do that
it's a lot better than it was though, right?
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:47 UTC
i'm trying right now in VS
not sure if its lot better
still memory gets up substantially over time
2016-03-05_18-48-23.png
Steven Kirk
@grokys
Mar 05 2016 17:50 UTC
105mb is a lot better than before though right? before it climbed easily to +500mb
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:50 UTC
yes the increase was much more rapid
Steven Kirk
@grokys
Mar 05 2016 17:51 UTC
i have a suspicion that the remaining rise is due to not using weak references in bindings
i'm going to implement that
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 17:53 UTC
ok
Wiesław Šoltés
@wieslawsoltes
Mar 05 2016 18:16 UTC
2016-03-05_19-15-29.png
Steven Kirk
@grokys
Mar 05 2016 19:15 UTC
nearly done that, but @kekekeks' WeakSubscriptionManager doesn't support unsubscribing
gotta leave soon but @kekekeks if you see this and have 5 mins, you could always add unsubscribe ;)
Darnell Williams
@Seeker1437
Mar 05 2016 19:15 UTC
hehe x3
Darnell Williams
@Seeker1437
Mar 05 2016 22:12 UTC
I find it weird how perspex handles rendering when both a margin and a width are specified
(or height¥
lately I have reverted to just using margins for now but it throw me off when text that should fit in a button shows one character per line and is partically lost
all because of the width
(or height)
Are there any suggestions for layout in Perspex?
the
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 23:11 UTC
@grokys good news. I resolved all my issues regarding non-working Grid and now finally I can test that use case
Grid measure time from 1200-1500 ms reduced to nearly 5-15 ms
Nikita Tsukanov
@kekekeks
Mar 05 2016 23:12 UTC
wow
danwalmsley
@danwalmsley
Mar 05 2016 23:12 UTC
wow
:D
Denis Zaporozhets
@QuantumDeveloper
Mar 05 2016 23:13 UTC
but my measuring implementation has one not resolved yet issue) not all row/col spans variations working (especially with auto-auto rows/cols.
@kekekeks @danwalmsley thanks)
Darnell Williams
@Seeker1437
Mar 05 2016 23:42 UTC
nice omg :D