These are chat archives for AvaloniaUI/Avalonia

16th
Jun 2016
Wiesław Šoltés
@wieslawsoltes
Jun 16 2016 08:33

@wieslawsoltes have you had any problems with bindings? since latest update

@danwalmsley Did not notice any, but was focused on testing virtualization, I will do more testing and report.

Nikita Tsukanov
@kekekeks
Jun 16 2016 09:59
Guys, please, check that new target exe detection works for you
I'm even getting downvoted
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:36
typeof(Blablabla).MakeGenericType
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:36
let me explaing a bit more
during the parsing, I gather the items in a ArrayList
later on, when all the children are read, I need to create an ImmutableList<T>
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:37
typeof(ImmutableList<>).MakeGenericType(mySuperItemType).GetMethod("Create", BindingFlags.Public|BindingFlags.Static).Invoke(null, new object[]{mySuperList})
You probably will need to create a regular list first
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:38
OK, but mySuperList is ArrayList
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:38
Then you need to detect your item type
And create a proper list
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:38
in runtime it fails
OK, how do I perform a dynamic Cast?
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:38
And then use IList::AddRange (not IList<T>, just IList)
You don't
ArrayList doesn't support IList<T>
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:39
So should I gather items in a Collection<object>?
instead?
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:39
Look, you need to somehow prepare a typed array of items
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:40
yes! but I'm out of luck with it :(
I don't know how
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:40
That's actually pretty simple
Array.CreateInstance(myItemType, length)
Then you can cast it to IList
And set your elements
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:41
Uhmm, let me check!
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:41
(or just use Array.Copy, it should support type casting, I think)
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:42
but while I'm gathering items, I need to add them to a Collection<object> I think
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:57
   [Fact]
    public void Test1()
    {
        var original = new Collection<object> { 1, 2, 3, 4, };
        var result = CreateImmutable(original, typeof(int));
    }

    private IEnumerable CreateImmutable(IEnumerable original, Type type)
    {
        var makeGenericType = typeof(ImmutableList<>).MakeGenericType(type);
        var methodInfo = makeGenericType.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);

        return (IEnumerable) methodInfo.Invoke(null, new object[] {original});
    }
that doesn't work :(
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:57
Obviously it doesn't
José Manuel Nieto
@SuperJMN
Jun 16 2016 11:57
hahaha
Nikita Tsukanov
@kekekeks
Jun 16 2016 11:58
ImmutableList<T>.Create wants T[] not Collection<object>
You need to prepare that T[] first
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:01
whooops, it says that methodInfo is null
Create doesn't exist
I'm in .NET Core
however, this seems to do it
var immutable = ImmutableList<int>.Empty.AddRange(original.Cast<int>());
Nikita Tsukanov
@kekekeks
Jun 16 2016 12:03
Well, you still need a typed collection first
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:03
yes
what's the best method to get it?
Nikita Tsukanov
@kekekeks
Jun 16 2016 12:03
or at least call Enumerable.Cast
on your arraylist
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:04
yes, but in the case of calling to Cast<T>, the T is runtime only
Nikita Tsukanov
@kekekeks
Jun 16 2016 12:07
reflection is your friend
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:11
I'm working!
Progressing!
Nikita Tsukanov
@kekekeks
Jun 16 2016 12:26
@grokys I have an idea for designer support for styles
We could have Design.StyleSubstitute property
So people could write something like
<StyleCollection>
     <Design.StyleSubstitute>
          <Button>Test</Button>
     </Design.StyleSubstitute>
</StyleCollection>
Designer will display the button with style collection applied
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:33
@kekekeks How could I get the Cast extension method?
the equivalent to var typed = untyped.Cast<T>();
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:34
Thank you, master!
Nikita Tsukanov
@kekekeks
Jun 16 2016 12:35
Yay, fixed image resource loading in designer
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:49
Done!
José Manuel Nieto
@SuperJMN
Jun 16 2016 12:54
 public class ImmutabilityTests
    {
        [Fact]
        public void Test1()
        {
            var original = new Collection<object>() { 1, 2, 3, 4, };
            var result = original.AsImmutable(typeof(int));

            Assert.NotEmpty(result);
            Assert.IsAssignableFrom<ImmutableList<int>>(result);
        }
    }



    public static class ReflectionExtensions
    {
        public static IEnumerable AsImmutable(this IEnumerable collection, Type elementType)
        {
            var typedCollection = ToTyped(collection, elementType);

            var resultType = typeof(ImmutableList<>).MakeGenericType(elementType);
            var result = resultType.GetField("Empty").GetValue(null);
            var addRange = resultType.GetMethod("AddRange");
            result = addRange.Invoke(result, new[] { typedCollection });
            return (IEnumerable)result;
        }

        private static object ToTyped(IEnumerable original, Type type)
        {
            var method = typeof(Enumerable).GetMethod("Cast", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(type);

            return method.Invoke(original, new[] { original });
        }
    }
Worky!
Andrey Kunchev
@donandren
Jun 16 2016 13:00
@kekekeks designer is not working fro me in the part of preview the views, I'll try to understand why and make a PR if I can fix it
Steven Kirk
@grokys
Jun 16 2016 13:00
I have an idea for designer support for styles
do you think you could add an issue describing the problems with styles?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:00
Yep, you can't preview them when editing them
i. e. Button.xaml in Avalonia.Controls
Steven Kirk
@grokys
Jun 16 2016 13:01
i'm busy right now and i'll miss any conversation about it
Andrey Kunchev
@donandren
Jun 16 2016 13:01
I mean for user controls, there is no selection for target exe
think i've found it what's the reason
trying to debug the extension and will give you more accurate details
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:03
Selection is only shown if there are multiple executables that reference your assembly
@SuperJMN for some reason omnixaml won't allow me to have attached property for Styles
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:07
O_O others work, but Styles don't?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:08
I think the issue is that Styles isn't an AvaloniaObject
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:08
please, check it
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:08
So convention-base SetXXX/GetXXX methods on another class are being ignored
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:09
probably!
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:10
Is there any workaround for that?
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:10
Who's the owner of the Styles attached property?
I'm a bit lost right regarding AvaloniaUI
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:12
Styles is a class
Which isn't AvaloniaObject, just a list
I have Design class
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:12
OK, how does the piece of XAML look like?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:12
And I want to have Design.Something to be a uniform attached property
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:12
Design.Styles?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:13
<Styles>
    <Design.DesignSubstitute>blablabla</Design.DesignSubstitute>
</Styles>
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:13
OK.
Then you need a pair of static methods in the Design classs
  • Design.SetDesignSubstitute(object instance, object value)
  • Design.GetDesignSubstitute(object instance)
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:14
Yep, I do have them
They are being ignored for some reason
        public static void SetDesignSubstitute(object target, Control control)
        {
            Substitutes.Remove(target);
            Substitutes.Add(target, control);
        }

        public static Control GetDesignSubstitute(object target)
        {
            Control rv;
            Substitutes.TryGetValue(target, out rv);
            return rv;
        }
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:15
let me check!
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:15
It might be me and my solution rebuild issues through
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:16
does it change something to change it to public static void SetDesignSubstitute(object target, object control) ?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:17
Yep, build issues
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:17
OK!
so it works?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:17
No)
OmniXaml.LoadException: Error loading XAML: OmniXaml.ParseException: Expected End Tag
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:17
I have some tests in OmniXAML to test attachable members
argh
can you show me the XAML?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:18
<Styles xmlns="https://github.com/avaloniaui">

    <Design.DesignSubstitute>
        <Button></Button>
    </Design.DesignSubstitute>
  <Style Selector="TabControl.sidebar">
  </Style>
</Styles>
It seems that the issue is Styles being a collection
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:19
Whoops, maybe the parsing isn't working fine because it doesn't like the mix of tags
Remove the <Style Selector ... part
<Style Selector=... />
<Styles xmlns="https://github.com/avaloniaui">

    <Design.DesignSubstitute>
        <Button></Button>
    </Design.DesignSubstitute>

</Styles>
does it work?
I think we haven't tested that scenario: a collection with an attached property inside
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:22
Yep, it doesn't allow me to mix attached properties and nested content elements
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:23
That's it!
da*m!
Styles is a collection
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:24
yep
José Manuel Nieto
@SuperJMN
Jun 16 2016 13:24
and we only have covered the case when the "hosting" object isn't a collection
the parser goes crazy with that :S
It's like an unexpected token
I think it tried to parse the attachable property as an item in the collection. I have to fix that!
Maybe you could wrap Styles inside another class that isn't a collection for now
Woohoo! I have a working test that uses immutable collections in OmniXAML!
the new Object Assembler is going to be wild!
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:35
@grokys
I was talking about that
Design.DesignSubstitute was supposed to be set on Styles, but there is a bug in omnixaml
Steven Kirk
@grokys
Jun 16 2016 13:38
ah ok, i understand - yeah that's cool
not sure about the name StyleSubstitute but i like the idea
though i wonder if it could be guessed?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:40
It shows an instruction what to do
When attibute is missing
(I know about the typo, too lazy to recompile)
Steven Kirk
@grokys
Jun 16 2016 13:40
ah ok
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:41
For now the code looks first in Styles then in every Style for that attribute
And uses the first one
Steven Kirk
@grokys
Jun 16 2016 13:41
what i mean though - is if you see a style with a selector of a plain control class couldn't you just use that class?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:41
That's until bug in omnixaml is fixed
Well, you want to preview your style
And for styles to apply in other xaml files
You need to recompile
Steven Kirk
@grokys
Jun 16 2016 13:43
ah ok, so this avoids recompilation...
kinda good but i'm not sure how often that will come up in real life
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:43
Well, it was easy to implement
Steven Kirk
@grokys
Jun 16 2016 13:43
if you're writing a style for a control you're writing a style for that control, not another control
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:43
Even no need to change vs extension
hm
Have you ever restyled WPF controls?
Steven Kirk
@grokys
Jun 16 2016 13:44
i have yeah, a fair bit - what use-case do you have in mind?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:45
When you want to create a custom theme for your application for example
There are tons of tyles in your custom theme file
And you add some test UI to preview your changes
So usually it will be MyCustomStyles.xaml and something big as design substitute
Steven Kirk
@grokys
Jun 16 2016 13:46
ah ok, so it's less writing templates for controls but writing themes
yeah that could be useful
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:46
If you are writing control template you still can reference said control as designsubstitute, no worries
Steven Kirk
@grokys
Jun 16 2016 13:47
could we change the name though, maybe Design.PreviewWith or something would be clearer?
Nikita Tsukanov
@kekekeks
Jun 16 2016 13:47
PreviewSurrogate
Steven Kirk
@grokys
Jun 16 2016 13:48
hmm, "surrogate" doesn't add anything there to me
PreviewControl?
though tbh PreviewWith says what it's going to do pretty clearly to me
it's going to preview the style with the control
Should be ok, I think
And everything that was needed to add design support
I'm not sure what we should do with App class
There is obviously nothing to preview there
Steven Kirk
@grokys
Jun 16 2016 13:59
yeah that looks good to me
for app class just hide the preview pane, or display a message i'd say
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:03
Well, one still want to see xaml load errors in App class, so we should also replace it on DesignerAssist level
Steven Kirk
@grokys
Jun 16 2016 14:10
oh yeah i forgot errors are displayed there
it's so cool that we're going to be able to preview control themes in the designer!
that's going to be incredibly useful
Andrey Kunchev
@donandren
Jun 16 2016 14:46
@kekekeks I've found the solution of the problem of the designer in my case
exe projects are in solution folder and then they are not found from the designer
I've made the nessesary changes to fix that problem
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:47
Ehm
Andrey Kunchev
@donandren
Jun 16 2016 14:47
PR for designer?
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:47
Update your extension
Andrey Kunchev
@donandren
Jun 16 2016 14:47
also fixed the enum value intelisense
i'll update and see is there any changes after my last update
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:48
Solution folder scan was included there AvaloniaUI/PerspexVS@5622706
For some reason visual studio doesn't show updates
so you have to manually remove and reinstall
Andrey Kunchev
@donandren
Jun 16 2016 14:49
yea i've made the same thing basically
but haven't updated master obviously
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:49
ahahah
Andrey Kunchev
@donandren
Jun 16 2016 14:49
lol
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:49
And what happened to intellisense?
Andrey Kunchev
@donandren
Jun 16 2016 14:52
donandren/PerspexVS@a2e18d1
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:53
It's more canonical to have True and False in XAML
Andrey Kunchev
@donandren
Jun 16 2016 14:53
ok not a problem
i'll fix it
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:57
merged
Andrey Kunchev
@donandren
Jun 16 2016 14:57
i've fixed it not sure what's you've merged but doesn't matter to me
can we make in designer the combo to show also a None value to target exe's so there will be no design preview
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:58
You can already hide preview
Andrey Kunchev
@donandren
Jun 16 2016 14:58
if we want to use only the paml intelisense and sometimes the designer locks files
ah i haven't noticed it that's nice option
Nikita Tsukanov
@kekekeks
Jun 16 2016 14:59
Select "Design" and click on that "-" button
Andrey Kunchev
@donandren
Jun 16 2016 14:59
I'll try it
thanks for the info
Wiesław Šoltés
@wieslawsoltes
Jun 16 2016 15:35
@kekekeks When Default document view: is set to Source View there is issue with designer control rendered over source view.
Nikita Tsukanov
@kekekeks
Jun 16 2016 15:35
I guess it's because it's a windows forms control or something
Wiesław Šoltés
@wieslawsoltes
Jun 16 2016 15:36
Przechwytywanie.PNG
When you move spliter little bit control gets positioned correctly.
I think this control in Source View should be hidden.
Nikita Tsukanov
@kekekeks
Jun 16 2016 15:38
It seems that we need some help from @abdelkarim
Wiesław Šoltés
@wieslawsoltes
Jun 16 2016 15:39
@kekekeks I've been testing Target project, I have 3 projects referencing my PCL
Nikita Tsukanov
@kekekeks
Jun 16 2016 15:39
So does it work properly?
Wiesław Šoltés
@wieslawsoltes
Jun 16 2016 15:39
But it always renders using Direct2D
Nikita Tsukanov
@kekekeks
Jun 16 2016 15:39
Yeah
Rendering subsystem is hardcoded for design mode
As well as windowing one
Wiesław Šoltés
@wieslawsoltes
Jun 16 2016 15:41
ok
other than this it works
Looks like the issue with control being rendered over source view is caused by broken spliter
When you start with split view than you can not move spliter to get design view only
it always switches to source view
Nikita Tsukanov
@kekekeks
Jun 16 2016 15:45
well, you can select "Design" "button" and click "collapse"
Honestly, I have no idea how that new splitter actually works