These are chat archives for AvaloniaUI/Avalonia

31st
Dec 2018
Kermalis
@Kermalis
Dec 31 2018 00:45
I actually don't know if what I want is possible, since IsPointerOver is {get;} instead of {get;set;}
Jeremy Koritzinsky
@jkoritzinsky
Dec 31 2018 00:56
You should be able to have a one-way-to-source binding from IsPointerOver to your view model.
Kermalis
@Kermalis
Dec 31 2018 01:26
Well what I want is to be able to run a callback when IsPointerOver changes on the UI thread (when my button is hovered I'd like to run some code in the class) then change the IsPointerOver value of other buttons to match, so they all look hovered at the same time
I don't know how to run a callback when it changes though, that's the part I don't see how I can do
Jeremy Koritzinsky
@jkoritzinsky
Dec 31 2018 01:40
Hmm you could trigger it on the setter. Or you could use AvaloniaBehaviors with the DataTriggerBehavior and the CallMethodAction.
Kermalis
@Kermalis
Dec 31 2018 01:44
Can I get an example?
Jeremy Koritzinsky
@jkoritzinsky
Dec 31 2018 02:07
I'm only on mobile now so I can't pull together an example. I'll see if I have a chance tonight.
ksigne
@ksigne
Dec 31 2018 08:21
hem, ItemsPresenterBase is prioritized on using .ItemsTemplate from TemplatedParent rather then ItemsPresenterBase itself
but in all Styles there is {TemplateBinding ItemsTemplate} on ItemsPresenter
is it a mistake or made intentionally?
ahopper
@ahopper
Dec 31 2018 09:18
@Kermalis I don't think changing IsPointerover for other buttons is a good idea even if it is possible as it would likely mess up the way it is set and unset. I think you need some other way to trigger them to have the same look as the pointerover state. You can use events in the code behind or binding as @jkoritzinsky said to detect in a view model.
Kermalis
@Kermalis
Dec 31 2018 09:20
I don't know how to do that though lol
ahopper
@ahopper
Dec 31 2018 09:30
In code behind you could subscribe to isPointerOver for your button
mybutton.WhenAnyValue(x => IsPointerOver).Subscribe(x=> do something);
Might not be spot on, away from real computer
ahopper
@ahopper
Dec 31 2018 09:38
to bind IsPointerOver="{Binding myispointerover, Mode=OneWayToSource}" in your button xaml
Benedikt Stebner
@Gillibald
Dec 31 2018 09:42
I would introduce a property in your ViewModel with a set get and introduce a style with a selector for that property on your button. Then you should be able to achieve what you want.
ahopper
@ahopper
Dec 31 2018 09:52
off the top of my head I'm not sure how to make a Property selector work with the DataContext/ view model
Kermalis
@Kermalis
Dec 31 2018 10:21
thanks
Some custom behaviors you can also use
You can create your own it's pretty simple, see the custom behaviors
ksigne
@ksigne
Dec 31 2018 12:23
Cannot really understand how styles work now
When there was just checking all selectors it was at least understandable
e.g. if I make ```
<Style Selector="ContextTab > TabItem:selected"> <Setter Property="HeaderTemplate"> <DataTemplate> <Grid Opacity="0.5"> <StackPanel Orientation="Vertical" Margin="28,7,28,0"> <TextBlock Text="{Binding}" Foreground="#D9D9D9" FontSize="16" FontHorizontalSpacing="0.92" VerticalAlignment="Top" FontWeight="SemiBold"/> <Rectangle Margin="0,2,0,0" Height="2.5" Fill="#8089A8"/> </StackPanel> </Grid> </DataTemplate> </Setter> </Style>
and then try to reference Grid with selector <Style Selector="ContextTab > TabItem Grid"> <Setter Property="Opacity" Value="1"/> </Style>
it won't be matched
?
ksigne
@ksigne
Dec 31 2018 13:12
ok, I got it, value inside template has higher priority than style one
but still can't find which class is being fired to set property
Benedikt Stebner
@Gillibald
Dec 31 2018 14:09
I think FormattedTextImplText needs to use an embedded font to get the same result on all platforms. Currently some tests are failing on Linux and MacOS because they don't produce the same measures. Will try to investigate this further on Ubuntu. I don't have a MacOS(VM) machine so I will not be able to test this for MacOS.
ksigne
@ksigne
Dec 31 2018 14:28
any reason to not add Padding to StackPanel?
Benedikt Stebner
@Gillibald
Dec 31 2018 14:52
Padding only makes sense in a 1:1 relation in my opinion. You get the same when you wrap your panel inside a Border, ContentControl, etc.
ksigne
@ksigne
Dec 31 2018 15:08
Why? Imagine you use StackPanel with brushed background
You can make background border-only through this deduction
Benedikt Stebner
@Gillibald
Dec 31 2018 16:26
How would you expect the children be arranged with a padding defined? Is there a spacing between children as well or just a spacing outside of all children? The later is achieved with a control that is wrapping everything. The first is achieved with a ItemTemplate. A panel is just responsible for arranging children. Arranging the panel is the task of an other control. That's how everything works with that kind of layout system. I guess it is always better to keep things as simple as possible. Maybe I am just used to that behavior.
ksigne
@ksigne
Dec 31 2018 16:27
ItemTemplate is not an optionhere
AFAIK panels doesn't have ItemTemplate so you end up with wrapping everything into ItemsControl.Item
Benedikt Stebner
@Gillibald
Dec 31 2018 16:28
You can always have a custom ItemsControl that has padding support and has a StackPanel as your ItemsPanel. That's how most controls support padding. As far as I know the only controls that support padding directly are Border and ContentPresenter.
ksigne
@ksigne
Dec 31 2018 16:29
Now I just have custom panel
Benedikt Stebner
@Gillibald
Dec 31 2018 16:30
Do you have some xaml to share?
ksigne
@ksigne
Dec 31 2018 16:31
what kind of xaml?
Benedikt Stebner
@Gillibald
Dec 31 2018 16:36
Just to have some context about what you want to achieve. I don't understand the background issue you would have with a wrapping control.
ksigne
@ksigne
Dec 31 2018 16:37
I want to achieve following: <Toolbar><ToolbarButton/>…</Toolbar>
The easiest way I see is to make Toolbar a custom panel, that's what I've did :D
Benedikt Stebner
@Gillibald
Dec 31 2018 16:40
In my opinion you should use ItemsControl to support templates and bindings etc.
What does your panel do with a padding value?
ksigne
@ksigne
Dec 31 2018 16:42
Same if you wrap stack panel into contentpresenter and set background on it. But you don't need separating these two and complexifying visual tree and xaml
Benedikt Stebner
@Gillibald
Dec 31 2018 16:47
Now I understand what you want to achieve. If the behavior would be the same with every panel implementation it could make sense to add padding to Panel.
ksigne
@ksigne
Dec 31 2018 16:47
Yeah, it will
But AFAIU panel itself doesn't have any measure/arrange implementation
So anyway you end up with changing every derivative of panel
Jonas Jermann
@jjermann
Dec 31 2018 16:48
hmm, depending if I have selected an item or not it should be displayed in a different way, is there a way to "propagate" IsSelected down to the corresponding selectedItem vm?
for instance setting IsSelected = true if it's selected
or how is this usually done?
ksigne
@ksigne
Dec 31 2018 16:53
what's vm?
i change template in style on :selected pseudoclass
but it might require tweaking in Avalonia.Controls if there's none observing for template changing...
for some controls there is, for some there's none
Benedikt Stebner
@Gillibald
Dec 31 2018 16:54
Just bind the IsSelected property of your item to your ViewModel
ksigne
@ksigne
Dec 31 2018 16:56
ah, i got the idea. you can connect item VM to whole context VM and then use () => context.SelectedItem.DataContext == this
Benedikt Stebner
@Gillibald
Dec 31 2018 16:57
@ksigne If panel implements this logic every concrete implementation could just call that implementation. In theory this logic could be added to the LayoutHelper for better reuse and code share.
Jeremy Koritzinsky
@jkoritzinsky
Dec 31 2018 17:00
Don't forget you can add a custom style Class to the panel and add the selector to use that. Then it would only affect those ones.
ksigne
@ksigne
Dec 31 2018 17:01
yes you can, but AFA panel is not TemplatedControl you can't control layout inside using styles
so you can't use style anyhow to convert StackPanel into Border->StackPanel
you can use ItemsControls but you can't add controls directly into <ItemsControl>
Benedikt Stebner
@Gillibald
Dec 31 2018 17:04
Then just use ListBox and apply a custom template.
ksigne
@ksigne
Dec 31 2018 17:05
ListBox has selectable mixin by default, that's not you expect from toolbar
Benedikt Stebner
@Gillibald
Dec 31 2018 17:06
The ideal would be a custom control that inherits from ItemsControl as i mentioned above. That way you can add items directly.
ksigne
@ksigne
Dec 31 2018 17:07
How inherit from ItemsControl so you can add items directly?
Benedikt Stebner
@Gillibald
Dec 31 2018 17:13
That should just work. You only have to define a default template.
Just inherit from ItemsControl instead of SelectingItemsControl and leave out the content part.
PART_ItemsPresenter is responsible for displaying everything.
Jonas Jermann
@jjermann
Dec 31 2018 17:22
hmm I have a datatemplate for the items
I could add an IsSelected property but how would I keep this up-to-date?
ksigne
@ksigne
Dec 31 2018 17:24
in WPF i used things like listBox.SelectedItem == this
Jonas Jermann
@jjermann
Dec 31 2018 17:24
SelectedItem I have
but that's on the "container" not in the item itself
I could subscribe to selection changes and recalculate IsSelected for all items in the container.
Jonas Jermann
@jjermann
Dec 31 2018 17:32
            this.WhenAnyValue(x => x.SelectedItemOnMyContainer)
                .ForEachAsync(selected => {
                    foreach (var entry in AllItemsOnMyCountainer)
                    {
                        entry.IsSelected = entry == selected;
                    }
                });
ahopper
@ahopper
Dec 31 2018 17:33
listboxitem has a :selected pseudoclass that can be used to style selected items
Jonas Jermann
@jjermann
Dec 31 2018 17:38
hmm, I'm not sure how this would work in my example (?)
the items are displayed using datatemplates
ahopper
@ahopper
Dec 31 2018 17:40
you can change the datatemplates or parts on the pseudoclass
ksigne
@ksigne
Dec 31 2018 17:43
@jjermann you can just pass reference to container one-time and then compare
Jonas Jermann
@jjermann
Dec 31 2018 17:43
@ahopper: Is there an example somewhere?
Jonas Jermann
@jjermann
Dec 31 2018 17:51
in particular how would I set a property on the item?
ahopper
@ahopper
Dec 31 2018 17:51
not exactly what you want but might give some clues
<ListBox.Styles>

         <Style Selector="ItemTemplate.favline:pointerover">
          <Setter Property="DataTemplate" >
            <StackPanel Classes="fav" Orientation="Horizontal">
              <Button Classes="LinkButton" Command="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl},
                             Path=DataContext.GotoFavoriteCommand}" CommandParameter="{Binding}">
              <StackPanel Orientation="Horizontal">
                <TextBlock Width="80" Text="{Binding name}"></TextBlock>
                <TextBlock Width="40" Text="{Binding modulation}"></TextBlock>
                <TextBlock Width="60" Text="{Binding frequency}"></TextBlock>
              </StackPanel>
              </Button>
              <Button Command="{Binding $parent[5].DataContext.radio.GotoFavoriteCommand}" CommandParameter="{Binding}">
               <TextBlock Text="+" ToolTip.Tip="Open in new receiver"></TextBlock>
            </Button>
            </StackPanel>
          </Setter>
        </Style>

      </ListBox.Styles>
Jonas Jermann
@jjermann
Dec 31 2018 17:52
happy new year (soon)! :)
ahopper
@ahopper
Dec 31 2018 17:53
yep you could just change some inner styles, sorry party guests arriving so I have to go and be polite. See you all next year.
happy new year to all, I have a feeling it will be an exciting one for Avalonia.