These are chat archives for AvaloniaUI/Avalonia

25th
Mar 2018
jp2masa
@jp2masa
Mar 25 2018 00:19
when I try to apply an ItemTemplate to Menu, it doesn't work, but if I replace Menu with TreeView the template works correctly, is this expected? I tried using DataTemplate and TreeDataTemplate, and both work on TreeView but not on Menu
MonkAlex
@MonkAlex
Mar 25 2018 09:52
Need help =_=
In wpf i use ListCollectionView, after some changes in items just invoke Refresh and items re-filtered.
In avalonia i use IReactiveDerivedList, invoke Reset - but it reset scroll position and view go to start.
Any idea, how to save view position? As view used ListBox
MonkAlex
@MonkAlex
Mar 25 2018 09:58
Hm, only reset not change position.
Reset drop selecteditems, when i restore it - position reseted.
Eli Arbel
@aelij
Mar 25 2018 11:44
@grokys "afaik in WPF the adorner layer doesn't accept input either" - it does. It's just like any other control.
Is there a sample for using ResourceDictionary? I can't get it to work. First, how do you load a XAML dictionary file in App.xaml (there's no Source property)? Second, if I use code to load the dictionary, StaticResource throws: "Value '(unset)' (of type Avalonia.AvaloniaProperty+Unset) is not of or convertible to type"
Steven Kirk
@grokys
Mar 25 2018 12:42
@aelij yeah we need to some documentation on ResourceDictionary. to add a XAML dictionary, you do a similar thing to what you do with including styles:
<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    <ResourceInclude Source='resm:MyApp.resources.xml'/>
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Eli Arbel
@aelij
Mar 25 2018 12:44
Thanks! And the other part? :) StaticResource doesn't work - but DynamicResource does.
Steven Kirk
@grokys
Mar 25 2018 12:45
could you give me a sample, not sure what you mean
Eli Arbel
@aelij
Mar 25 2018 12:45
I wrote the exception I got: Value '(unset)' (of type Avalonia.AvaloniaProperty+Unset) is not of or convertible to type
Steven Kirk
@grokys
Mar 25 2018 12:45
yeah, what did you do to get this exception?
Eli Arbel
@aelij
Mar 25 2018 12:45
Just {StaticResource Something}
Steven Kirk
@grokys
Mar 25 2018 12:46
but you said " if I use code to load the dictionary" so there's something more to it
Eli Arbel
@aelij
Mar 25 2018 12:46
I'll try with ResourceInclude. Currently the dictionary is loaded in code using AvaloniaXamlLoader
Steven Kirk
@grokys
Mar 25 2018 12:46
or are you just saying {StaticResource} doesn't work?
StaticResource only works within the confines of a XAML file
as the resource is looked up while parsing the xaml
Eli Arbel
@aelij
Mar 25 2018 12:48
I'll be more specific. I added code to App.xaml.cs to load the dictionary into the Application.Resources property, then in MainWindow.xaml, I added {StaticResource X} which thew the exception. When I changed it to {DyanamicResource X} it worked.
Steven Kirk
@grokys
Mar 25 2018 12:48
regarding adorners, we set IsHItTestVisible to false in AdornerLayer: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Primitives/AdornerLayer.cs#L24
ok yeah that won't work. does that work in WPF?
Eli Arbel
@aelij
Mar 25 2018 12:49
Sure
Why doesn't it work?
StaticResource uses the XAML parser's ambient context to look up a resource
if you're not loading a resource via XAML then it won't be there
Eli Arbel
@aelij
Mar 25 2018 12:50
But Application is a resource node, isn't it?
Steven Kirk
@grokys
Mar 25 2018 12:50
hmm yeah you might have a point there
Eli Arbel
@aelij
Mar 25 2018 12:52
Regarding AdornerLayer, so there's no reason I shouldn't be able to change the default right? Adorners are interactive quite often: in a drawing canvas they can be used as resize hooks, in validation they can have tooltips.
Steven Kirk
@grokys
Mar 25 2018 12:53
yeah you should be able to change the default
maybe it shouldn't be hit test invisible by default?
Eli Arbel
@aelij
Mar 25 2018 12:55
I think so. That's WPF's default
Steven Kirk
@grokys
Mar 25 2018 12:56
weird, i could've sworn WPF's adorners weren't hit test visible. wonder where i got that from?
Eli Arbel
@aelij
Mar 25 2018 12:58
Oh well, it's an easy fix :)
Steven Kirk
@grokys
Mar 25 2018 12:59
i'll add an issue
Steven Kirk
@grokys
Mar 25 2018 13:05
@aelij just tried adding this unit test:
        [Fact]
        public void Locates_Resource_Added_In_Code_Before_Xaml_Loaded()
        {
            var xaml = @"
<UserControl xmlns='https://github.com/avaloniaui'
             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <UserControl.Resources>
        <SolidColorBrush x:Key='brush' Color='{StaticResource color}'/>
    </UserControl.Resources>

    <Border Name='border' Background='{StaticResource brush}'/>
</UserControl>";

            var loader = new AvaloniaXamlLoader();
            var userControl = new UserControl();

            userControl.Resources.Add("color", Color.FromUInt32(0xff506070));
            loader.Load(xaml, userControl);

            var border = userControl.FindControl<Border>("border");
            var brush = (SolidColorBrush)border.Background;
            Assert.Equal(0xff506070, brush.Color.ToUint32());
        }
and it seems to work
ahhh. you were loading a different dictionary right? not just adding the resource to the dictionary
Eli Arbel
@aelij
Mar 25 2018 13:06
It works with dynamic so my guess is yeah :)
Could you try putting the static resource deeper? I.e. not a direct child where the resources are. Just a guess...
Steven Kirk
@grokys
Mar 25 2018 13:11
just tried it with adding a merged dictionary in code and it works too... what do you mean by "not a direct child where the resources are"?
Eli Arbel
@aelij
Mar 25 2018 13:18
I mean not a direct child. e.g. <UserControl><Border><Border Background="..." />
Steven Kirk
@grokys
Mar 25 2018 13:19
ok
so the lookup that failed was the StaticResource on the control not in the resource dictionary?
Eli Arbel
@aelij
Mar 25 2018 13:19
BTW I'm using version 0.6.1, not master
Yeah, on a control, just like your sample.
I'll try switching to ResourceInclude and see if it makes a difference
Steven Kirk
@grokys
Mar 25 2018 13:20
yeah just tried that and it works too...
one more thing
Eli Arbel
@aelij
Mar 25 2018 13:20
Oh, I think I understand
The control that's loaded is not the same control where the resources are added. It's a child
That has its own Xaml load
Steven Kirk
@grokys
Mar 25 2018 13:21
ahhhh
Eli Arbel
@aelij
Mar 25 2018 13:21
That doesn't work in WPF either - but I also tried at the Application level - and that should work
Steven Kirk
@grokys
Mar 25 2018 13:22
you added a control with it's own xaml load to app.xaml?
Eli Arbel
@aelij
Mar 25 2018 13:23
No :) It's so hard to explain in words...
Do you have Skype? I can share my screen
Steven Kirk
@grokys
Mar 25 2018 13:26
i've got to pop out any minute... will be around in a bit though
Eli Arbel
@aelij
Mar 25 2018 13:26
I'll try to write a test that fails
Steven Kirk
@grokys
Mar 25 2018 13:26
don't suppose you can distill the problem down into a short snippet?
yeah that would be great
Eli Arbel
@aelij
Mar 25 2018 13:26
ResourceInclude doesn't solve the problem btw
Steven Kirk
@grokys
Mar 25 2018 13:27
ok
Eli Arbel
@aelij
Mar 25 2018 13:27
Yeah I'll create a small repro
Eli Arbel
@aelij
Mar 25 2018 13:40
Alas, it works in the repro :) I'll try to figure out what's different
Eli Arbel
@aelij
Mar 25 2018 13:54
Hmm, it works with a SolidColorBrush but doesn't work with Drawing
And it works when directly referenced by a control, but not from a data template
Steven Kirk
@grokys
Mar 25 2018 13:56
hm, strange
Eli Arbel
@aelij
Mar 25 2018 13:57
I'll send you a repro project
MonkAlex
@MonkAlex
Mar 25 2018 16:13
OpenFolderDialog has two properties - initialdirectory and defaultdirectory. What the difference?