These are chat archives for AvaloniaUI/Avalonia

8th
May 2018
Wiesław Šoltés
@wieslawsoltes
May 08 2018 04:58
@boombuler
Rayyan Tahir
@RayyanTahir
May 08 2018 06:54
How to add ControlTemplate.Triggers to a ControlTemplate in Avalonia?
ahopper
@ahopper
May 08 2018 06:55
@jkoritzinsky thanks for looking, I've added an issue
Steven Kirk
@grokys
May 08 2018 07:44
@RayyanTahir we don't have tiggers at the moment. you can usually use styles to achieve the same thing. what is it you need to do?
Rayyan Tahir
@RayyanTahir
May 08 2018 07:45
I have a TabItem with a ControlTemplate and I want to change it's appearance based on its IsSelected property
danwalmsley
@danwalmsley
May 08 2018 07:56
@RayyanTahir i found tab control to be a little broken, this is how I achieved the same thigh though https://github.com/VitalElement/AvalonStudio/blob/develop/AvalonStudio/AvalonStudio/Controls/TabControlView.paml
Rayyan Tahir
@RayyanTahir
May 08 2018 07:56
Thanks, by broken did you mean an exception related to TabPanel?
Because I'm also getting that exception mentioned in detail below:
System.NotSupportedException: Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{https://github.com/avaloniaui}TabPanel'
   at Portable.Xaml.Schema.XamlTypeInvoker.ThrowIfUnknown()
   at Portable.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments)
   at Portable.Xaml.XamlObjectWriterInternal.InitializeObjectIfRequired(Boolean waitForParameters, Boolean required)
   at Portable.Xaml.XamlObjectWriterInternal.OnWriteStartObject()
   at Portable.Xaml.XamlWriterInternalBase.WriteStartObject(XamlType xamlType)
   at Portable.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
   at Portable.Xaml.XamlWriter.WriteNode(XamlReader reader)
   at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
   at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter)
   at Avalonia.Markup.Xaml.AvaloniaXamlLoader.LoadFromReader(XamlReader reader, AvaloniaXamlContext context, IAmbientProvider parentAmbientProvider)
   at Avalonia.Markup.Xaml.Templates.TemplateContent.Load()
   at Avalonia.Markup.Xaml.Templates.TemplateContent.Load(Object templateContent)
   at Avalonia.Markup.Xaml.Templates.ControlTemplate.Build(ITemplatedControl control)
   at Avalonia.Controls.Primitives.TemplatedControl.ApplyTemplate()
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Grid.MeasureOverride(Size constraint)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Grid.MeasureOverride(Size constraint)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Border.MeasureOverrideImpl(Size availableSize, IControl child, Thickness padding, Thickness borderThickness)
   at Avalonia.Controls.Border.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Grid.MeasureOverride(Size constraint)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Grid.MeasureOverride(Size constraint)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Border.MeasureOverrideImpl(Size availableSize, IControl child, Thickness padding, Thickness borderThickness)
   at Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Decorator.MeasureOverride(Size availableSize)
   at Avalonia.Controls.Primitives.AdornerDecorator.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Controls.Border.MeasureOverrideImpl(Size availableSize, IControl child, Thickness padding, Thickness borderThickness)
   at Avalonia.Controls.Border.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
   at Avalonia.Controls.Window.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutManager.Measure(ILayoutable control)
   at Avalonia.Layout.LayoutManager.ExecuteInitialLayoutPass(ILayoutRoot root)
   at Avalonia.Controls.Window.Show()
   at Avalonia.DesignerSupport.DesignWindowLoader.
Steven Kirk
@grokys
May 08 2018 08:03
@RayyanTahir TabControl is broken because TabItem means both the tab header and the tab content
so there's no way to style just the header or just the content
the error you're getting above: Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{https://github.com/avaloniaui}TabPanel'
is because TabPanel isn't a class in Avalonia
Rayyan Tahir
@RayyanTahir
May 08 2018 08:04
Right, thanks
Steven Kirk
@grokys
May 08 2018 08:05
use a TabStrip and a Carousel bound together instead of a TabControl. see here https://github.com/AvaloniaUI/Avalonia/issues/536#issuecomment-240649272
then to style an item in the TabStripwhen it's selected you can just create a style with the selector TabItem:selected
Rayyan Tahir
@RayyanTahir
May 08 2018 08:07
You mean TabStripItem:selected?
According to the example in the link:
<TabStrip Grid.Row="0"  Name="TestStrip">
      <TabStripItem Content="TabName1" />
      <TabStripItem Content="TabName2" />
      <TabStripItem Content="TabName3" IsEnabled="False" Foreground="LightGray" />
    </TabStrip>
danwalmsley
@danwalmsley
May 08 2018 08:10
@RayyanTahir the link iv posted to AvalonStudio shows a working example of what @grokys is suggesting
Rayyan Tahir
@RayyanTahir
May 08 2018 08:11
Yes, thank you I read that.
Also, just to clear my confusion, if I wanted to use a ControlTemplate for TabStripItem, what will be the Avalonia way for adding pseudoclasses/selectors to that ControlTemplate?
Steven Kirk
@grokys
May 08 2018 08:16
the default template adds a :selected style for the TabStripItem: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Default/TabStripItem.xaml
is that what you're wanting to do?
Rayyan Tahir
@RayyanTahir
May 08 2018 08:18
Right, in that example, if the ControlTemplate had a Grid inside with a name (say "MainGrid"), then in the second style with pseudoclass how do I change the property of that Grid?
e.g. <Style Selector="TabStripItem:pointerover /template/ Grid#MainGrid">
Rayyan Tahir
@RayyanTahir
May 08 2018 08:20
Got it, thank you so much @grokys and @danwalmsley :)
danwalmsley
@danwalmsley
May 08 2018 11:30
@Gillibald I'm getting `System.MissingFieldException: 'Field not found: 'Avalonia.Controls.Primitives.TemplatedControl.FontFamilyProperty'.' on your PR, its a caught exception but could this be a problem?
Benedikt Schroeder
@Gillibald
May 08 2018 11:44
@danwalmsley Will check that
danwalmsley
@danwalmsley
May 08 2018 11:45
@Gillibald sorry I got confused with avaloniaedit code
Benedikt Schroeder
@Gillibald
May 08 2018 11:45
Typeface already has an overload for FontFamily
Just tested a small scenario quiet possible that something goes wrong. Have to add some unit tests. But will probably add fallbacks first.
danwalmsley
@danwalmsley
May 08 2018 11:54
iv realised the exception is that avalonia edit will need recompiling against your new code
so don't worry about that
ok I'm getting an exception when calling
TextBlock.SetFontFamily(this, "Segoi UI");
Benedikt Schroeder
@Gillibald
May 08 2018 11:56
Try TextBlock.SetFontFamily(this, new FontFamily("Segoi UI");
danwalmsley
@danwalmsley
May 08 2018 11:56
ok
btw does this uri look ok?
resm:AvalonStudio.Controls.Standard.CodeEditor.Assets.SourceCodePro-Regular.ttf#Source Code Pro;assembly=AvalonStudio.Controls.Standard
not sure about the location of ;assembly= part
that doesn't work however
@Gillibald that api only accepts string
Benedikt Schroeder
@Gillibald
May 08 2018 11:58
@danwalmsley The last part of the definition should only be the name of the font but i can change that behavior to work with your syntax
danwalmsley
@danwalmsley
May 08 2018 11:58
no that's ok
it works perfectly if I use
resm:AvalonStudio.Controls.Standard.CodeEditor.Assets.SourceCodePro-Regular.ttf;assembly=AvalonStudio.Controls.Standard#Source Code Pro
Benedikt Schroeder
@Gillibald
May 08 2018 12:00
public static void SetFontFamily(Control control, string value) should be public static void SetFontFamily(Control control, FontFamily value) will change that
danwalmsley
@danwalmsley
May 08 2018 12:01
@Gillibald ok if I delete the font installed on my system it doesn't use the embedded font it just fallsback to system font
do you have some test fonts that are not installed to try at your end
that's skia btw
Benedikt Schroeder
@Gillibald
May 08 2018 12:03
I am not on my dev machine right now. If your FreeType supports your FontStyle and FontWeight it should work.
Will check your font this evening
danwalmsley
@danwalmsley
May 08 2018 12:06
iv also tried
FontFamily="resm:AvalonStudio.Assets.SourceSansPro-Regular.ttf#Source Sans Pro"
but I end up with
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:07
@grokys TabControl is pure evil, I was trying to do some stuff with drag and drop and its a mess :worried: Ended up using TabStrip.
Steven Kirk
@grokys
May 08 2018 12:07
yeah i think we should remove it
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:07
In the process I have found some issues with Carousel control when using IsVirtualized="False"
danwalmsley
@danwalmsley
May 08 2018 12:08
image.png
I'm guessing we need to always specify assembly=
Benedikt Schroeder
@Gillibald
May 08 2018 12:09
Thats a bug will check that
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:09
@grokys I have Items property bound to collection and I drag and drop items between two Carousel controls. Sometime wrong DataTemplate is applied.
danwalmsley
@danwalmsley
May 08 2018 12:09
@Gillibald ParseParameters just returns null
Steven Kirk
@grokys
May 08 2018 12:11
@wieslawsoltes could you add an issue. it's not something i've seen before.
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:11

yeah i think we should remove it

@grokys I just checked, I like 50 times used TabControl in my app.

Steven Kirk
@grokys
May 08 2018 12:11
yeah that's why i've not actually removed it yet :/
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:11

@wieslawsoltes could you add an issue. it's not something i've seen before.

@grokys I will report, but this was discovered yesterday at night :smile:

I have some new code using drag and drop :fire:
This is poor's man docking control in making using for TabStrip+Drag&Drop
danwalmsley
@danwalmsley
May 08 2018 12:14
@wieslawsoltes :)
I've been thinking of starting on docking control in next few days
perhaps we should base it on something like this?
does this allow to drag from one panel control to another?
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:15
Yes
Inside panel and between panels
danwalmsley
@danwalmsley
May 08 2018 12:15
ok I have to try this
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:15
All works
Except issue with Carousel control
danwalmsley
@danwalmsley
May 08 2018 12:15
when you do that, is it moving the datacontext
and then recreating the control
or moving the control with the datacontext?
I manipulate view model collection bound to Items
Actually pretty simple stuff
I do the same thing with ListBox and TreeView :fire:
All is done in DropBehavior class.
danwalmsley
@danwalmsley
May 08 2018 12:18
so that would recreate the control right?
behaviors are so nice :)
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:18
Hm
danwalmsley
@danwalmsley
May 08 2018 12:18
I'm just thinking for a docking control like with an editor
you can move your editorViewmodel
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:18
Is probably resuses container in Carousel
If you drop into same TabStrip
danwalmsley
@danwalmsley
May 08 2018 12:19
if not I guess it recreates
ok cool
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:19
I guess it comes how caching is done in Avalonia control
I do not manipulate logical/visual tree manually
danwalmsley
@danwalmsley
May 08 2018 12:20
iv been debating in my head what you would need to full docking
I cant work out if you can do what you have done there
or if you need to detach from visual tree and re-connect at the place your dropped to
that might be a bit weird with carousel, etc
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:21
danwalmsley
@danwalmsley
May 08 2018 12:21
ok will try it out now
thanks
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:21
I would prefer docking with full MVVM approach
It makes easier for loading/saving stuff, manipulating
danwalmsley
@danwalmsley
May 08 2018 12:21
I'm mainly thinking of a control like code editor
if you move it mvvm way, might be inefficient?
Jumar Macato
@jmacato
May 08 2018 12:22
@wieslawsoltes @danwalmsley i'm planning to attempt porting AvalonDock when time permits :)
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:22
I use ImmutableArray for collections, the benefit is than I have full UNDO/REDO for my layout changes :fire:
Basically for free
You can try this in Core2D today
I discover views using Autofac IoC
I want EditorControl layout to be defined in code, not sure how this will be implemented but thats the goal.
Jumar Macato
@jmacato
May 08 2018 12:29
@wieslawsoltes Prism still is quite useful after all these years eh
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:29
For sure
I am just reinventing the wheel here probably :smile:
Jumar Macato
@jmacato
May 08 2018 12:29
perhaps, but you'd learn more if you do haha
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:30
With Xaml and data binding its easy to do some crazy stuff
Anyway it works so I am happy with it :smile:
Jumar Macato
@jmacato
May 08 2018 12:34
Haha indeed, it's the most powerful aspect of wpf & avalonia
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:35
Try doing some C++ and MFC and you will quickly realize how powerful is AvaloniaUI and XAML :smile:
Jumar Macato
@jmacato
May 08 2018 12:35
i sure did, i would never wanna go back to that hahaha
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:35
Jumar Macato
@jmacato
May 08 2018 12:36
wooh WxWidgets
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:36
The MFC version is so much worse
In AvaloniaUI I can do this in few minutes
Jumar Macato
@jmacato
May 08 2018 12:36
such nightmarish code :scream:
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:37
Well its all generated :fire:
Actually I have idea for GUI designer for Avalonia , based on my experience with WxWidgets
Jumar Macato
@jmacato
May 08 2018 12:37
what a mess that is , bud
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:38
Yeah and try statically compile it under windows :smile:
There is no dotnet publish for this
danwalmsley
@danwalmsley
May 08 2018 12:38
@grokys that properties overhaul PR has broken somethings for me
Jumar Macato
@jmacato
May 08 2018 12:39
@wieslawsoltes good heavens, that's such a productivity killer
danwalmsley
@danwalmsley
May 08 2018 12:39
I'm going to try and add a repro for the issue its causing me
Wiesław Šoltés
@wieslawsoltes
May 08 2018 12:39
@jmacato I want to rewrite this app with Avalonia someday :smile:
Jumar Macato
@jmacato
May 08 2018 12:40
@wieslawsoltes i hope you can find the time, patience and willpower to do so :D
Steven Kirk
@grokys
May 08 2018 12:42
@danwalmsley probably
Steven Kirk
@grokys
May 08 2018 13:11
what broke?
danwalmsley
@danwalmsley
May 08 2018 13:15
I think its some styles getting applied
Rayyan Tahir
@RayyanTahir
May 08 2018 13:17
@danwalmsley Is there a way to programmatically bind an ObservableCollection to ItemsControl from C#?
In WPF it was ItemsSource I think
danwalmsley
@danwalmsley
May 08 2018 13:18
yes, but I think @grokys will answer better than me, normally I do it from XAML
here we bind Items
Rayyan Tahir
@RayyanTahir
May 08 2018 13:19
Okay, thanks
danwalmsley
@danwalmsley
May 08 2018 13:19
so in XAML you can simply do <ItemsControl Items="{Binding ...}"
if that's enough to answer your question
the c# I'm not sure of
Rayyan Tahir
@RayyanTahir
May 08 2018 13:19
Yes I'm familiar with the approach, was just looking for the alternate c# approach
danwalmsley
@danwalmsley
May 08 2018 13:21
Rayyan Tahir
@RayyanTahir
May 08 2018 13:21
I'll check
danwalmsley
@danwalmsley
May 08 2018 13:21
it might be something like
var control = new Control
{
    [!Property2] = observableCollection,
}
but I cant be sure
Rayyan Tahir
@RayyanTahir
May 08 2018 13:24
I'll look into it in detail. As for XAML approach, is there a way to bind to ObservableCollection but with condition e.g {Binding Path=MyObservable.Where(w=>w.type==1)}
Jumar Macato
@jmacato
May 08 2018 13:24
I'd suggest having a separate property for that :)
Rayyan Tahir
@RayyanTahir
May 08 2018 13:25
Yeah that would be one approach, but if a conditional approach exists why not use it? :P
danwalmsley
@danwalmsley
May 08 2018 13:25
@RayyanTahir I'm just finding you some info 2 secs
Rayyan Tahir
@RayyanTahir
May 08 2018 13:26
Sure, thanks!
danwalmsley
@danwalmsley
May 08 2018 13:27
ok I think this would do that very well
reactiveui is baked into avalonia anyhow
so you wont be bringing in another dependency that isn't there already
Rayyan Tahir
@RayyanTahir
May 08 2018 13:28
Oh nice, so I should create two separate derived collections of the parent collection and use the derived in my XAML right?
danwalmsley
@danwalmsley
May 08 2018 13:29
I believe that's how it works its a while since I used it
Rayyan Tahir
@RayyanTahir
May 08 2018 13:29
Alright, thanks I'll try it
danwalmsley
@danwalmsley
May 08 2018 13:31
anyone seen this
interesting
Rayyan Tahir
@RayyanTahir
May 08 2018 13:46
@danwalmsley I was finally able to perform binding in C# like following:
ItemsControl.Bind(ItemsControl.ItemsProperty, new Binding() {Source = MyObservable.Where(w => w.Type == Types.SomeType) });
danwalmsley
@danwalmsley
May 08 2018 14:11
@grokys ok iv managed to produce a repro of the properties overhaul
#1568 iv got 2 branches
1 with and 1 without the properties overhaul to show how it breaks
Steven Kirk
@grokys
May 08 2018 14:11
thanks @danwalmsley !
danwalmsley
@danwalmsley
May 08 2018 14:12
iv a feeling it has broken style selectors that use ... /template/ ... but not sure on anything more than that
Steven Kirk
@grokys
May 08 2018 14:12
@RayyanTahir you should be able to simplify a bit: ItemsControl.Bind(ItemsControl.ItemsProperty, MyObservable.Where(w => w.Type == Types.SomeType));
Rayyan Tahir
@RayyanTahir
May 08 2018 14:16

Thank you, but that gives me

Argument 2: cannot convert from 'System.Collections.Generic.IEnumerable<Team>' to 'System.IObservable<object>'

Steven Kirk
@grokys
May 08 2018 14:16
oh, so MyObservable isn't an IObservable?
ahhh. it's an ObservableCollection ok
Rayyan Tahir
@RayyanTahir
May 08 2018 14:17
Its an ObservableCollection
:D
Steven Kirk
@grokys
May 08 2018 14:17
that's going to cause problems
Rayyan Tahir
@RayyanTahir
May 08 2018 14:18
Should I use ReactiveList instead of ObservableCollections for my bindings?
Steven Kirk
@grokys
May 08 2018 14:18
first of all, you're passing a lazily evaluated IEnumerable into ItemsControl.Items so every time the control wants to enumerate the items, it's going to re-evaluate
secondly it won't react to changes in the observable collection
you'll want to use a ReactiveUI derived list: https://reactiveui.net/docs/handbook/collections/derived-lists
Rayyan Tahir
@RayyanTahir
May 08 2018 14:19
Right, will do
Wiesław Šoltés
@wieslawsoltes
May 08 2018 16:29
Carousel.PNG
@grokys This is Carousel bug I was talking about before.
This happens when I change Items collection after view was created.
Wiesław Šoltés
@wieslawsoltes
May 08 2018 16:36
I think when you have IsVirtualized="False" than caching is broken.
Wiesław Šoltés
@wieslawsoltes
May 08 2018 17:19
@grokys I have repro!
AvaloniaUI/Avalonia#1569
Wiesław Šoltés
@wieslawsoltes
May 08 2018 17:34
The ItemsChanged event in CarouselPresenter gets NotifyCollectionChangedAction.Reset action when there is already one panel child materialized :worried:
Wiesław Šoltés
@wieslawsoltes
May 08 2018 18:27
Until issue is fixed I have switched to ContentControl
Steven Kirk
@grokys
May 08 2018 18:34
oh ok, thanks for investigating @wieslawsoltes - sounds like it'll be easy enough to fix
Wiesław Šoltés
@wieslawsoltes
May 08 2018 18:34
I hope so :smile:
Benedikt Schroeder
@Gillibald
May 08 2018 19:18
Is it a used feature to load fonts from filesystem?
@danwalmsley I have checked your fonts and couldn't see any issue they just worked. Fixed minor Bugs but it should work in general. Fallbacks for FontFamily comes next.
danwalmsley
@danwalmsley
May 08 2018 19:26
@Gillibald can you confirm if the fonts were also installed on your system when you tried?
Benedikt Schroeder
@Gillibald
May 08 2018 19:27
They were not installed i can try if you want.
I dont use an extra cache for Skia i just add TypeFaces to the existing cache maybe i should change that. That way we avoid problems with installed fonts. Direct2D1 already has an extra cache.
Benedikt Schroeder
@Gillibald
May 08 2018 19:37
What is the official default font of Avalonia? Have found different definitions.
Jeremy Koritzinsky
@jkoritzinsky
May 08 2018 21:01
I don't think we have one. Which ones have we been using?
danwalmsley
@danwalmsley
May 08 2018 21:46
@Gillibald I shall have another go with your PR tomorrow, I might need you to check what iv done though because I wasn't having a lot of luck
Have you tried fonts within namespace like this
First.Second.Folder.Folder?
I couldn't get the font to resolve