These are chat archives for AvaloniaUI/Avalonia

24th
Aug 2017
Matthijs ter Woord
@mterwoord
Aug 24 2017 11:06
got my avalonia based app working on raspberry, using .net core. awesome start of the weekend! :)
Steven Kirk
@grokys
Aug 24 2017 11:26
excellent @mterwoord !
regarding your IsPressed PR - i'm wondering whether a better way might be to provide e.g. control.GetClassObservable(":pressed")
that way you can easily get the state of any class
so if you wanted to make the focus control the visibility of something etc you could easily do it
Matthijs ter Woord
@mterwoord
Aug 24 2017 11:29
@grokys Sounds great, but would that allow me to bind poperties? yes, rght?
Steven Kirk
@grokys
Aug 24 2017 11:29
yeah, you can bind properties to observables
though maybe not in markup
Matthijs ter Woord
@mterwoord
Aug 24 2017 11:32
just asking
what I want to do, is control an engine with a push button. as long as its pressed, it should run
:)
Wiesław Šoltés
@wieslawsoltes
Aug 24 2017 13:49
You can bind Pressed and Released events to commands using behaviors , all can be done from markup
Or even invoke methods on view model
Wiesław Šoltés
@wieslawsoltes
Aug 24 2017 15:06
ah the PointerPressed and PointerReleased released events for button do not fire for left button :worried: probably of Click event
Wiesław Šoltés
@wieslawsoltes
Aug 24 2017 15:16
otherwise this would be possible
<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
             xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions">
    <Grid RowDefinitions="Auto,*" ColumnDefinitions="*">
        <Button x:Name="button" Content="Press Me" Width="100" Height="50" Grid.Row="1" Grid.Column="0" Margin="5,0,0,5" HorizontalAlignment="Center" VerticalAlignment="Center">
            <i:Interaction.Behaviors>
                <ia:EventTriggerBehavior EventName="PointerPressed" SourceObject="{Binding #button}">
                    <ia:CallMethodAction TargetObject="{Binding}" MethodName="IncrementCount"/>
                </ia:EventTriggerBehavior>
                <ia:EventTriggerBehavior EventName="PointerReleased" SourceObject="{Binding #button}">
                    <ia:CallMethodAction TargetObject="{Binding}" MethodName="DecrementCount"/>
                </ia:EventTriggerBehavior>
            </i:Interaction.Behaviors>
        </Button>
    </Grid>
</UserControl>
Steven Kirk
@grokys
Aug 24 2017 15:18
yeah, same on other XAML frameworks https://stackoverflow.com/a/23040891/6448
Wiesław Šoltés
@wieslawsoltes
Aug 24 2017 15:19
yep I have checked WPF :smile:
Wiesław Šoltés
@wieslawsoltes
Aug 24 2017 15:24
you can do this :fire:
<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
             xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions">
    <Grid RowDefinitions="Auto,*" ColumnDefinitions="*">
        <Border x:Name="button" Background="{StyleResource GreenBrush}" Width="100" Height="50" Grid.Row="1" Grid.Column="0" Margin="5,0,0,5" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Border.Styles>
                <Style>
                    <Style.Resources>
                        <SolidColorBrush x:Key="RedBrush">Red</SolidColorBrush>
                        <SolidColorBrush x:Key="GreenBrush">Green</SolidColorBrush>
                    </Style.Resources>
                </Style>
            </Border.Styles>
            <i:Interaction.Behaviors>
                <ia:EventTriggerBehavior EventName="PointerPressed" SourceObject="{Binding #button}">
                    <ia:ChangePropertyAction TargetObject="{Binding #button}" PropertyName="Background" Value="{StyleResource RedBrush}"/>
                    <ia:CallMethodAction TargetObject="{Binding}" MethodName="IncrementCount"/>
                </ia:EventTriggerBehavior>
                <ia:EventTriggerBehavior EventName="PointerReleased" SourceObject="{Binding #button}">
                    <ia:ChangePropertyAction TargetObject="{Binding #button}" PropertyName="Background" Value="{StyleResource GreenBrush}"/>
                    <ia:CallMethodAction TargetObject="{Binding}" MethodName="DecrementCount"/>
                </ia:EventTriggerBehavior>
            </i:Interaction.Behaviors>
            <TextBlock Text="Click Me" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>
    </Grid>
</UserControl>
2017-08-24_17-25-13.gif
Eli Arbel
@aelij
Aug 24 2017 16:43
I always thought this syntax was horrible. Can't we do something like <Border PointerPressed="{Binding DecrementCount}" />?
I.e. bind directly to a method. WPF actually added a similar feature in later version but never had a complete implementation. http://blogs.microsoft.co.il/pavely/2012/04/07/wpf-45-markup-extension-for-events/
Steven Kirk
@grokys
Aug 24 2017 16:49
yeah i'd love to have that
and yeah i find behavior syntax horrible as well
i much prefer codebehind to behaviors
Steven Kirk
@grokys
Aug 24 2017 17:14
btw, i'm close to finishing adding Control.Resource + StaticResource + DynamicResource and also fixing #492 to allow referencing resource across XAML files
StyleResource will be going away at some point as now resources aren't just stored in styles
Johan Larsson
@JohanLarsson
Aug 24 2017 17:20
One thing I often miss when writing attached properties is a registered event
Steven Kirk
@grokys
Aug 24 2017 19:43
what do you mean by a registered event @JohanLarsson ?
Johan Larsson
@JohanLarsson
Aug 24 2017 19:46
Attached is probably closer to what I mean. Something like:
private static void OnAttached(DependencyObject attachedElement)
{
    ...
}
Eli Arbel
@aelij
Aug 24 2017 20:11
There was indeed a bug in win32 mouse wheel handling, it wasn't just the scroll viewer background - it got the wrong coordinates so hit testing didn't work properly. Fixed in #1132
Steven Kirk
@grokys
Aug 24 2017 20:12
wow @aelij you're on a roll!
Eli Arbel
@aelij
Aug 24 2017 20:12
Haha, yeah :) Got some free time
Steven Kirk
@grokys
Aug 24 2017 20:14
btw why "Button ClickMode.Repeat (instead of RepeatButton)"?
RepeatButton would make more sense to me tbh, as it's kinda little-used functionality for a standard button
Eli Arbel
@aelij
Aug 24 2017 20:16
I thought about it. But because there's no ButtonBase, inheriting from Button would've been more difficult. And all this really adds is an uninitialized DispatcherTimer field in the case of a standard button.
Steven Kirk
@grokys
Aug 24 2017 20:25
ah ok. so that's what ButtonBase is for ;)
Eli Arbel
@aelij
Aug 24 2017 20:28
Maybe I will add it. I'm for being more compliant with WPF
Eli Arbel
@aelij
Aug 24 2017 20:40
BTW, I had to copy an entire template because I couldn't set a Grid's ColumnDefinitions in style. Any way around that? :)
Steven Kirk
@grokys
Aug 24 2017 20:45
what were you trying to do exactly?
Eli Arbel
@aelij
Aug 24 2017 20:47
For the scroll bar, i used a grid with rows "10,*,10". If it's a horizontal one, I wanted to change it to columns "10,*,10"
I guess I could use a DockPanel instead, and change the Dock proprty
Steven Kirk
@grokys
Aug 24 2017 20:50
hmm yeah that might be better
i don't think we have a good way to do that right now
Eli Arbel
@aelij
Aug 24 2017 20:51
Because it's a collection?
Steven Kirk
@grokys
Aug 24 2017 20:51
yeah
Eli Arbel
@aelij
Aug 24 2017 20:51
But it has a setter
Steven Kirk
@grokys
Aug 24 2017 20:51
oh yeah... ok you should be able to do that
Eli Arbel
@aelij
Aug 24 2017 20:52
Maybe all it needs is a direct prop definition
Steven Kirk
@grokys
Aug 24 2017 20:52
yeah, or to allow binding to plain CLR properties
for now though I'd use a DockPanel
our grid implementation is super-inefficent
Eli Arbel
@aelij
Aug 24 2017 20:53
Really? Good to know :)
Well, I don't see a #if GRID_PARANOIA in your code ;)
(in case you're unfamiliar, see this)
Steven Kirk
@grokys
Aug 24 2017 21:09
hahaha nice
i'd never seen that before