These are chat archives for AvaloniaUI/Avalonia

30th
Aug 2018
Siegfried Pammer
@siegfriedpammer
Aug 30 2018 08:32
I am trying to fix some more bugs in AvaloniaEdit... is there any documentation on how the event handling in Avalonia differs from WPF? How are the Pointer(Released|Pressed) events implemented? In my case I have the following hierarchy: TextEditor -> TextArea -> TextView. In WPF the PointerPressed event (or equivalent) would bubble up from the TextView to the TextArea. But in Avalonia the TextView.OnPointerPressed method never gets called, only the handlers registered to TextArea.PointerPressed. Can somebody shed some light on how to implement the AvalonEdit behavior in AvaloniaEdit? Thank you very much!
Wiesław Šoltés
@wieslawsoltes
Aug 30 2018 08:45
Siegfried Pammer
@siegfriedpammer
Aug 30 2018 08:46
so... there are no bubbling events?
Steven Kirk
@grokys
Aug 30 2018 10:11
@Gillibald yes we should probably have a HeaderedContentControl.HeaderTemplate
Should ContentPresenter.Content default to DataContext? -- I don't think so, why would you say it should?
@siegfriedpammer so... there are no bubbling events? yes, the default is bubbling
@WHumphreys I we any closer to having a new release? -- yes hopefully, maybe next month? not sure what everyone else thinks
Siegfried Pammer
@siegfriedpammer
Aug 30 2018 10:12
@grokys thanks... then there's something fishy going on...
Steven Kirk
@grokys
Aug 30 2018 10:13
sorry, i've not been home much in that last month, so not had much time for avalonia
Siegfried Pammer
@siegfriedpammer
Aug 30 2018 10:13
are there any tools like Snoop for Avalonia?
I guess not
Steven Kirk
@grokys
Aug 30 2018 10:13
now i'm going away again for a few days, but hopefully things should return to normal in september
@siegfriedpammer there's the F12 devtools
it's a bit basic
Siegfried Pammer
@siegfriedpammer
Aug 30 2018 10:14
OK
thanks
Steven Kirk
@grokys
Aug 30 2018 10:14
i've been experimenting with making it a bit better here https://github.com/grokys/devtools
Benedikt Schroeder
@Gillibald
Aug 30 2018 10:27

This is how I currently handle the Content and Header of TabItem:

if (tabItem.HeaderTemplate == null)
{
    tabItem[~HeaderedContentControl.HeaderTemplateProperty] = Owner[~ItemsControl.ItemTemplateProperty];
}

if (tabItem.Header == null)
{
    if (item is IHeadered headered)
    {
        if (tabItem.Header != headered.Header)
        {
            tabItem.Header = headered.Header;
        }
    }
    else
    {
        if (!(tabItem.DataContext is IControl))
        {
            tabItem.Header = tabItem.DataContext;
        }
    }
}

if (!(tabItem.Content is IControl))
{
    tabItem[~ContentControl.ContentTemplateProperty] = Owner[~TabControl.ContentTemplateProperty];
}

if (tabItem.Content == null)
{              
    tabItem[~ContentControl.ContentProperty] = tabItem[~StyledElement.DataContextProperty];
}

This works properly but I am not sure if it is the right way

You can see that I asign DataContext to Header | Content if non initial value is present. Shouldn't this happening by default if you use a ContentPresenter?
Steven Kirk
@grokys
Aug 30 2018 10:31
also i assume tabItem is a TabItem control, not a ContentPresenter?
the TabItem should have a ContentPresenter in its template that has a binding like the one in Button above
Benedikt Schroeder
@Gillibald
Aug 30 2018 10:59
<Styles xmlns="https://github.com/avaloniaui">
    <Style Selector="TabItem">
        <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderLightBrush}"/>
        <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="FontSize" Value="{DynamicResource FontSizeLarge}"/>
        <Setter Property="Foreground" Value="{DynamicResource ThemeForegroundLightBrush}"/>
        <Setter Property="TabStripPlacement" Value="{Binding $parent[TabControl].TabStripPlacement}"/>
        <Setter Property="Margin" Value="2 2 0 0"/>
        <Setter Property="Template">
            <ControlTemplate>
                <ContentPresenter
                    Name="PART_ContentPresenter"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    ContentTemplate="{TemplateBinding HeaderTemplate}"
                    Content="{TemplateBinding Header}"
                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                    Margin="{TemplateBinding Margin}"
                    Padding="{TemplateBinding Padding}"/>
            </ControlTemplate>
        </Setter>
    </Style>
    <Style Selector="TabItem:selected">
        <Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}"/>
    </Style>
    <Style Selector="TabItem:disabled">
        <Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}"/>
    </Style>
</Styles>
The template works the same but if I don't make the Content = DataContext asignment nothing is displayed what makes sense.
Benedikt Schroeder
@Gillibald
Aug 30 2018 11:06
public class TabItem : HeaderedContentControl, ISelectable
WojciechKrysiak
@WojciechKrysiak
Aug 30 2018 11:15
@siegfriedpammer depending on what you use in your edit control, maybe this will point you in the right direction: AvaloniaUI/AvaloniaEdit#61
Siegfried Pammer
@siegfriedpammer
Aug 30 2018 11:16
I had seen that change... sadly this is not related to e.Handled
The problem is that in AvalonEdit the events first "go through" TextView and then bubble up to TextArea and TextEditor... however in AvaloniaEdit this seems to be backwards... so TextArea gets to see the events first...
WojciechKrysiak
@WojciechKrysiak
Aug 30 2018 11:34
Ah, so yeah, it's something else entirely then
cm4ker
@cm4ker
Aug 30 2018 15:24
Hi folks! Have any chance get commits into Avalonia Portable.Xaml fork from main repo?
I push small fix cwensley/Portable.Xaml#108 what I need in my application.