These are chat archives for AvaloniaUI/Avalonia

28th
Nov 2016
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:36
Hi people! I need your help. Maybe @grokys' help
I have a problem with UserControls. They don't render anything
(using OX2)
(OmniXAML v2)
danwalmsley
@danwalmsley
Nov 28 2016 11:39
@SuperJMN can you post link to repo, of relevant code I will take a look :)
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:40
Of course! I was publishing the branch with the issue
(usercontrol_issue)
please, run Samples\OmniXamlV2App
the XAML is really simple:
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="special"
        xmlns:vm="using:AvaloniaApp.ViewModels;assembly=AvaloniaApp"
        Title="Avalonia Test Application" Width="800" Height="600"
        xmlns:local="using:AvaloniaApp;Assembly=AvaloniaApp">

    <local:MyUserControl></local:MyUserControl>
</Window>
and the UserControl is:
<?xml version="1.0" encoding="utf-8" ?>

<local:MyUserControl xmlns="https://github.com/avaloniaui"
               xmlns:local="using:AvaloniaApp;Assembly=AvaloniaApp">

    <Button>Hola</Button>

</local:MyUserControl>
The Window renders blank, but the UserControl is there: Window.Content is the correct instance, with everything inside
danwalmsley
@danwalmsley
Nov 28 2016 11:44
try putting button inside a Grid
see if that makes a differnece
I know you shouldn't have to
but I'm pretty sure iv come across a similar issue before
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:45
No worky :(
Steven Kirk
@grokys
Nov 28 2016 11:46
@SuperJMN has your UserControl got a template?
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:46
I'm checking!
Steven Kirk
@grokys
Nov 28 2016 11:47
check its visual children and the visual children of the visual children
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:48
no, it doesn't have a template. It's null!
nor has VisualChildren
it's dead
the question is... why?
Steven Kirk
@grokys
Nov 28 2016 11:50
ok, so that's the problem: you remember the previous problem you had where the window didn't have a template? you can use the same technique to work out why this doesn't
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:50
yes, I remember
but, where do UserControls get their template from?
the StyleKey for classes derived from UserControl is set to use the ContentControl template
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:52
aha!
thanks! I think I have enough info
let me see if I find out why it's not getting the template
OK, I have checked that this works:
<local:MyUserControl xmlns="https://github.com/avaloniaui"
               xmlns:local="using:AvaloniaApp;Assembly=AvaloniaApp">

    <local:MyUserControl.Template>
        <ControlTemplate>
            <ContentPresenter Name="PART_ContentPresenter"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}"
                        Padding="{TemplateBinding Padding}"/>
        </ControlTemplate>
    </local:MyUserControl.Template>

    <Grid>
        <Button>Hola</Button>
    </Grid>

</local:MyUserControl>
Setting the template directly
José Manuel Nieto
@SuperJMN
Nov 28 2016 11:57
for some reason, the Stle of the ContentControl isn't applied
Steven Kirk
@grokys
Nov 28 2016 11:58
right so to debug that you need to do what i showed you before
if (control.GetType().Name == "MyUserControl" && ((Setter)setter).Property.Name == "Template")
{
    System.Diagnostics.Debugger.Break();
}
before this line: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Styling/Styling/Style.cs#L93
José Manuel Nieto
@SuperJMN
Nov 28 2016 12:05
OK! I'm about to debug it
(real life job kicked in)
haha
José Manuel Nieto
@SuperJMN
Nov 28 2016 12:12
Argh, the breakpoint wasn't hit!
I mean, the Debugger didn't break :S
José Manuel Nieto
@SuperJMN
Nov 28 2016 12:43
OK, it applies the style to ContentControl, but not to UserControl
wow, not only it happens with UserControl, I have created a class derived from Button and the style isn't set
    public class MyButton : Button
    {        
    }
<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="special"
        xmlns:vm="using:AvaloniaApp.ViewModels;assembly=AvaloniaApp"
        Title="Avalonia Test Application" Width="800" Height="600"
        xmlns:local="using:AvaloniaApp;Assembly=AvaloniaApp">

    <local:MyButton>Hola</local:MyButton>

</Window>
José Manuel Nieto
@SuperJMN
Nov 28 2016 12:48
Could it be that the SelectorTypeConverter isn't creating the correct Selector?
José Manuel Nieto
@SuperJMN
Nov 28 2016 12:57
Oh man, I think I've found the problem
at least, one problem
José Manuel Nieto
@SuperJMN
Nov 28 2016 13:09
OK, I've fixed the problem, but the custom MyButton still doesn't get its style applied
I've uploaded the changes to the branch
Please, somebody take a look. It's here: https://github.com/SuperJMN/Avalonia-JMN/tree/usercontrol_issue
it seems like if styles doesn't apply to derived classes
José Manuel Nieto
@SuperJMN
Nov 28 2016 14:57
how do I create a selector for a prefixed type?
for instance, the type is local:MyButton
<Style Selector="local:MyButton" /> ??
Steven Kirk
@grokys
Nov 28 2016 14:59
@SuperJMN | is the namespace separator in style selectors, same as in CSS
José Manuel Nieto
@SuperJMN
Nov 28 2016 14:59
OK!
<Style Selector="local|MyButton">
with the pipe, then?
OK, I think I've created the Style for MyButton, but it's still not applied :(
José Manuel Nieto
@SuperJMN
Nov 28 2016 15:07
Should I use a special syntax to apply a Style to a type and its subtypes?
Steven Kirk
@grokys
Nov 28 2016 15:27
if you want it to apply to local:MyButton and also its subclasses you need to use :is(local|MyButton)
José Manuel Nieto
@SuperJMN
Nov 28 2016 16:15
OK, thanks :)
José Manuel Nieto
@SuperJMN
Nov 28 2016 17:58
argh, I haven't been able to fix the problem, yet
I'll take a look later, if I can
Steven Kirk
@grokys
Nov 28 2016 18:00
yeah, sorry been busy today so not had chance to take a look yet
José Manuel Nieto
@SuperJMN
Nov 28 2016 20:05
same for me :( I haven't had much time to fight on the Avalonia Arena
José Manuel Nieto
@SuperJMN
Nov 28 2016 20:16
it may be related to the lifecycle events (BeginInit and EndInit)
I have seen the style application happens according to those
José Manuel Nieto
@SuperJMN
Nov 28 2016 21:06
I'm almost sure that it's because when OmniXAML calls EndInit, the Parent still hasn't been set