These are chat archives for AvaloniaUI/Avalonia

28th
Aug 2015
Steven Kirk
@grokys
Aug 28 2015 07:19
hey @SuperJMN - nearly got everything working, however I've hit a problem
i'm trying to do simple loading of xaml similar to wpf without using all the OmniXaml advanced features
there is an InitializeComponent method like in WPF etc which calls PerspexXamlLoader.Load in https://github.com/grokys/Perspex/blob/alpha1/src/Markup/Perspex.Xaml.Desktop/PerspexXamlLoader.cs
that just translates the type to a URL and calls XamlLoader.Load(Stream)
however I get the error:

Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll

Additional information: Could not find file 'D:\projects\Perspex\samples\XamlTestApplication\bin\Debug\Window.xaml'.

even though I gave it a stream containing "MainWindow.xaml"
Steven Kirk
@grokys
Aug 28 2015 07:25
that should work, right?
José Manuel Nieto
@SuperJMN
Aug 28 2015 08:54
Hey! Good morning! Is the failing code committed to the branch?
Steven Kirk
@grokys
Aug 28 2015 08:55
yes, it is
José Manuel Nieto
@SuperJMN
Aug 28 2015 08:55
OK. I'll fix it
Steven Kirk
@grokys
Aug 28 2015 08:55
thanks!
José Manuel Nieto
@SuperJMN
Aug 28 2015 08:59
I still have to wash the dishes...
But after that, I'll put my hands to work
Steven Kirk
@grokys
Aug 28 2015 09:00
hahaha i can wait - working on my day job right now anyway ;)
José Manuel Nieto
@SuperJMN
Aug 28 2015 09:49
OK, fixed
I'm arranging the code a bit
Steven Kirk
@grokys
Aug 28 2015 09:50
wow that was fast!
sure, take your time!
José Manuel Nieto
@SuperJMN
Aug 28 2015 09:50
the thing is that...
you no longer need the PerspexXamlLoader!
because that is an special version of the XamlLoader
You will see :)
Steven Kirk
@grokys
Aug 28 2015 09:51
Yeah, i was wondering if that was the case
José Manuel Nieto
@SuperJMN
Aug 28 2015 09:51
by the way, since I haven't worked with embedded resources directly...
do they work with Uris?
or with plain and simple strings?
(for paths)
Steven Kirk
@grokys
Aug 28 2015 09:53
Well they just work with paths... But you need to be able to specify an assembly if the assembly isn't the entry assembly, so I guess that makes it a URL...
I don't want to use pack URLs though
It at least have an alternative
José Manuel Nieto
@SuperJMN
Aug 28 2015 09:54
OK, we should figure out
but since Uri can wrap almost everything routable, I think it's OK
we can just use the part of the Uri that is given to the method to transform it to our format of string
and change if needed
Steven Kirk
@grokys
Aug 28 2015 09:55
sure
José Manuel Nieto
@SuperJMN
Aug 28 2015 09:56
Should I post a pull request?
or just tell you the code I used?
then you can arrange it as you wish
(In WPF, the actual loading is made is public static void LoadComponent(object component, Uri resourceLocator))
Steven Kirk
@grokys
Aug 28 2015 09:58
If you could send a pr that would be great!
José Manuel Nieto
@SuperJMN
Aug 28 2015 09:58
the resource locator is in the form:
"/WpfApplication2;component/mainwindow.xaml"
OK!
Steven Kirk
@grokys
Aug 28 2015 10:00
Yeah that's a pack URL. They're horrible
José Manuel Nieto
@SuperJMN
Aug 28 2015 10:01
IPukeable
José Manuel Nieto
@SuperJMN
Aug 28 2015 10:34
hahaha, what a hell! I tried to create a LoadComponent into Application
and I discovered that it uses the full .NET Fx because things like Assembly.GetEntryAssembly
so I'm giving up
I'll put the code inside MainWindow and then you can refactor everything :P
Steven Kirk
@grokys
Aug 28 2015 10:36
ok :)
José Manuel Nieto
@SuperJMN
Aug 28 2015 10:36
It was going to look so nice, but... PCL stroke my ass
José Manuel Nieto
@SuperJMN
Aug 28 2015 10:45
PR sent!
Steven Kirk
@grokys
Aug 28 2015 10:46
thanks!
so the problem was simply that i was trying to use PerspexXamlLoader?
José Manuel Nieto
@SuperJMN
Aug 28 2015 10:50
yes
you're lowering the level
your talking directly with the XamlLoader

thanks!

nothing :D

Steven Kirk
@grokys
Aug 28 2015 11:04
awesome - i've moved PerspexParserFactory.cs out of Desktop because it wasn't actually using anything platform dependent
and now the Perspex.Xaml.Desktop project is empty ;)
José Manuel Nieto
@SuperJMN
Aug 28 2015 11:35
cool!
delete it
Steven Kirk
@grokys
Aug 28 2015 14:48
hey guys, could you try something for me?
or by going to Tools -> Extensions and Update -> Online and doing a search for PerspexVS
and then try doing a File -> New -> Project -> Perspex -> Perspex Application
add something to the xaml file
and see if it runs
José Manuel Nieto
@SuperJMN
Aug 28 2015 14:55
works like a fucking charm!!
Window with no title, but it works without touching ANYTHING
wow!
also, the icon isn't too fancy, haha
but it's so cool I'm gonna shout!
I've already told my friends to install the extension XD
Richard Simpson
@RichiCoder1
Aug 28 2015 15:35
I'll give it a try too soon :)
Richard Simpson
@RichiCoder1
Aug 28 2015 15:56
The xaml editor isn't happy with the namespace, but otherwise it worked like a charm. Awesome!
Steven Kirk
@grokys
Aug 28 2015 16:00
Excellent!
Once I've written a few did I think we can call that an alpha
Docs
Steven Kirk
@grokys
Aug 28 2015 16:45
and then need to get someone to design a logo ;)
i think the templates should show up in the New Project -> Online etc dialogs by they don't seem to
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:10

The xaml editor isn't happy with the namespace, but otherwise it worked like a charm. Awesome!

It isn't happy because it thinks it's for WPF!

We would need some custom XAML validator there... if it's possible, I can say it's deep inside my backlog :)
Steven Kirk
@grokys
Aug 28 2015 18:12
yeah, i think it's possible because xamarin forms manage it
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:12

Once I've written a few did I think we can call that an alpha

It's an alpha!

Steven Kirk
@grokys
Aug 28 2015 18:12
no idea how to do it though
yep! planning to announce the alpha on monday
no point doing it on a friday night ;)
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:12
I would like to tell the designer "hey, check this namespaces, not WPF's!"
yay! I'm excited!
by the way, I have my own mini-announcement
x:Name is working :D
Steven Kirk
@grokys
Aug 28 2015 18:13
excellent - need to put name scopes in perspex then
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:14
you may implement INameScope in your objects
only in the ones that you want to register your children
I've tested this XAML
<Window xmlns="root" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>
    <TextBlock x:Name="MyTextBlock" />
    <TextBlock x:Name="MyOtherTextBlock" />
  </Grid>
</Window>
if you ask Window.FindName("MyTextBlock") it will answer you with the first TextBlock, as expected :D
for now, you are required to use x:Name, not Name
Steven Kirk
@grokys
Aug 28 2015 18:18
it can't support the NameScope attached property yet then?
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:18
how does it work?
Steven Kirk
@grokys
Aug 28 2015 18:19
in wpf - you set this attached property https://msdn.microsoft.com/en-us/library/system.windows.namescope.namescopeproperty%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 on a control and the control becomes a namescope
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:20
Uhm, only controls that are INameScope are registered with their children
Steven Kirk
@grokys
Aug 28 2015 18:20
nope! ;)
try it
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:20
if Window is not INameScope, then... no children
I'm talking about OmniXAML
Steven Kirk
@grokys
Aug 28 2015 18:21
ah ok, so you're not going to implement it like WPF?
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:22
I would like to! but I'm not sure how WPF does it
Steven Kirk
@grokys
Aug 28 2015 18:22
the problem is that with templated controls, the root of the expanded template needs to be a namescope
and that control can be any type
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:23
OK, I understand
Steven Kirk
@grokys
Aug 28 2015 18:23
but i was thinking of just creating a NameScope control and always making that the root of the expanded template
only problem with that is that it will make the visual tree a lot deeper
so i think that's why WPF decided to use the attached property
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:25
I was sure that the XAML loader relies only in the INameScope interface
I will take a better look
How do you set the attached property?
I'm trying in WPF with this:
<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication2"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <NameScope.NameScope>
            <NameScope  />
        </NameScope.NameScope>
        <Button x:Name="Button"></Button>
    </Grid>
</Window>
to create a namescope for the Grid
Steven Kirk
@grokys
Aug 28 2015 18:30
tbh i've never tried to use it
does that not work?
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:35
No, it doesn't
I think the attached property is just a trick not related with XAML
I don't know :S
Steven Kirk
@grokys
Aug 28 2015 18:36
hmm, not sure either
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:37
all I've seen for WPF is that the parser just register names with the parent is a INameScope
maybe that's why they invented the DP
Steven Kirk
@grokys
Aug 28 2015 18:37
that can't be the whole story though, or lookless controls wouldn't work
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:37
to set a namescope to things that aren't inherently namescopes
Steven Kirk
@grokys
Aug 28 2015 18:38
let me try something
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:38
OK!
Steven Kirk
@grokys
Aug 28 2015 18:43
ok, if i create a button like so:
<Button Name="b" Click="b_Click">Test</Button>
and then:
    private void b_Click(object sender, RoutedEventArgs e)
    {
        var bChild = VisualTreeHelper.GetChild(this.b, 0);
        var isNameScope = bChild is INameScope;
        var nameScope = NameScope.GetNameScope(bChild);
    }
you will see that isNameScope is false but nameScope is set to an instance of TemplateNameScope
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:48
and what's the meaning of it? I'm a bit clogged today
that button is not a namescope?
Steven Kirk
@grokys
Aug 28 2015 18:50
no, the child of the button is a namescope
i.e. the templated child
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:51
so, the button has a namescope, but is not a namescope
is it?
Steven Kirk
@grokys
Aug 28 2015 18:51
yep
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:51
It seems to me that WPF does something under the hood
it's not obvious what happens
Steven Kirk
@grokys
Aug 28 2015 18:52
thing is, it seems to me that it must be the XAML system that does it
because if you create controls in code, they don't get added to namescopes
as mentioned in the link you posted
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:54
the question is, how does my parser know when a control is a namescope?
Steven Kirk
@grokys
Aug 28 2015 18:54
of that, i have no idea
how does System.Xaml know for that matter?
Steven Kirk
@grokys
Aug 28 2015 18:55
ahhh - there you go! :)
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:55
XamlTypes have a fucking LookIsNameScope!
then, PerspexXamlType should override the Lookup
and you can rely on your attached property
does it make sense?
Steven Kirk
@grokys
Aug 28 2015 18:59
yep, that sounds good
José Manuel Nieto
@SuperJMN
Aug 28 2015 18:59
then, I will complete the functionality!
Phase 1 completed
José Manuel Nieto
@SuperJMN
Aug 28 2015 19:06
Phase 2, the type lookup
I could get a living doing this...