These are chat archives for AvaloniaUI/Avalonia

30th
Nov 2016
José Manuel Nieto
@SuperJMN
Nov 30 2016 07:24
OK
yes, it's OK. Thanks!
José Manuel Nieto
@SuperJMN
Nov 30 2016 09:21
hey, one more question. Is it possible to create a binding from Image.Source to a string without a ValueConverter?
Darnell Williams
@Seeker1437
Nov 30 2016 10:55
Let's not use WPF system... doesn't that make ILMerge unusable?
Steven Kirk
@grokys
Nov 30 2016 11:12
yeah that's one of the problems with it - true!
José Manuel Nieto
@SuperJMN
Nov 30 2016 13:35
@SuperJMN sure! here https://github.com/AvaloniaUI/Avalonia/blob/master/samples/ControlCatalog/Pages/CarouselPage.xaml#L14
:) OK! but that's a direct value, my question was about a Binding, like <Image Source="{Binding ImagePath}" />
José Manuel Nieto
@SuperJMN
Nov 30 2016 14:27
And another question. Is there a control equivalent to WPF's Viewbox?
José Manuel Nieto
@SuperJMN
Nov 30 2016 14:34
I need something like Viewbox in a my application :)
danwalmsley
@danwalmsley
Nov 30 2016 14:38
@SuperJMN currently no
I think it should be fairly simple to implement
José Manuel Nieto
@SuperJMN
Nov 30 2016 14:56
I'm trying that right now, but since I'm new in this task, I'm dying :)
Do we have any porting guidelines? Like: UIElement => Control
DependencyProperty => StyledProperty or DirectProperty
(event handlers => blah blah...)
José Manuel Nieto
@SuperJMN
Nov 30 2016 15:01
(overrides like OnApplyTemplate, pretty common are translated to ??)
for instance, this:
        public override void OnApplyTemplate ()
        {
            ChildBorder = (Border) VisualTreeHelper.GetChild (this, 0);
            if (ChildBorder == null)
                throw new Exception ("Argh!");

            Scale = new ScaleTransform ();
            ChildBorder.RenderTransform = Scale;
            ChildBorder.Child = Child;
        }
José Manuel Nieto
@SuperJMN
Nov 30 2016 15:06
I don't know how to port it
danwalmsley
@danwalmsley
Nov 30 2016 16:13
@SuperJMN I'm not sure how the wpf one works, and we have to be careful not to be influenced by their code
but I was thinking something along the lines of...
1) In measure override work out the difference in scale between available space and the content...
then
2) Apply a RenderTransform to scale it to the available size
3) Return the available size as the size (Measure override)
probably an extension of grid?
as a very naïve implementation anyhow
OnApplyTemplate == OnTemplateApplied - the WPF naming was confusing as it suggests you can override the actual applying of the template
VisualTreeHelper.GetChild(this, 0) == this.GetVisualChildren().First()
that's an extension method so you have to using Avalonia.VisualTree
Steven Kirk
@grokys
Nov 30 2016 16:28
but that's not how it should be done anyway, the control you want to find should be a named control
Steven Kirk
@grokys
Nov 30 2016 16:33
you also can just get rid of DefaultTemplate - no other controls have that
but...
all of this is acedemic because ViewBox shouldn't be a templated control
Steven Kirk
@grokys
Nov 30 2016 16:42
yeah, don't use that control for a port: it's not correct
its says they got a lot of their code from http://silverlight.codeplex.com/ - try there instead
José Manuel Nieto
@SuperJMN
Nov 30 2016 17:38
@grokys I cannot find the code of Viewbox inside that link :(
Steven Kirk
@grokys
Nov 30 2016 17:39
i couldn't either :/
José Manuel Nieto
@SuperJMN
Nov 30 2016 17:40
Argh, it seems we have no sources to port, then
Steven Kirk
@grokys
Nov 30 2016 17:42
i can find mention of it being part of silverlight toolkit all over the internet though
José Manuel Nieto
@SuperJMN
Nov 30 2016 17:44
It's seems it's just a collection of features that didn't come in Silverlight, to extend it
Steven Kirk
@grokys
Nov 30 2016 17:51
yes, one of which appeared to be, at some point, ViewBox
José Manuel Nieto
@SuperJMN
Nov 30 2016 17:53
It's strange, but I found that control to be very useful for some scenarios
For instance, for face recognition, an image gives you a list of rectangles. Then, you have to represent the rectangles in the GUI
I do it using this XAML
<Viewbox Grid.Row="1">
            <Grid>
                <Image Source="{Binding Image, Converter={StaticResource UriToImageConv}}" />
                <ItemsControl ItemsSource="{Binding Faces}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Canvas />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="{x:Type FrameworkElement}">
                            <Setter Property="Canvas.Left" Value="{Binding FaceRectangle.Left}" />
                            <Setter Property="Canvas.Top" Value="{Binding FaceRectangle.Top}" />
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate DataType="{x:Type contract:Face}">
                            <Grid>
                                <Rectangle x:Name="Rectangle" Fill="#5100FFFF"
                                           Width="{Binding FaceRectangle.Width}"
                                           Height="{Binding FaceRectangle.Height}">
                                </Rectangle>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </Grid>

        </Viewbox>
José Manuel Nieto
@SuperJMN
Nov 30 2016 17:58
Basically, the Viewbox makes the inner Canvas and the Image keep in sync. They form a unit and the rectangles of each face render OK
This is the result
image.png
If I resize the Window, the rectangles fit the faces thanks to the Viewbox
image.png
Matthijs ter Woord
@mterwoord
Nov 30 2016 18:00
in wpf, you can fake that using a custom control....
it's sad to say, but i have code for that..
José Manuel Nieto
@SuperJMN
Nov 30 2016 18:01
It's more complex than that, right?
Matthijs ter Woord
@mterwoord
Nov 30 2016 18:01
?
José Manuel Nieto
@SuperJMN
Nov 30 2016 18:01
I mean, that requires only XAML
Matthijs ter Woord
@mterwoord
Nov 30 2016 18:01
i made the code i'm talking about before i knew of viewbox...
José Manuel Nieto
@SuperJMN
Nov 30 2016 18:02
Oh, not everybody knows that Viewbox is great for that kind of things
it's one of the less known controls
(along with the HeaderedContentControl and the ItemsControl :))
Steven Kirk
@grokys
Nov 30 2016 18:27
yeah, ViewBox is very useful, I agree
it would definitely be a good thing to have!
i don't think it should be too difficult to implement
Wiesław Šoltés
@wieslawsoltes
Nov 30 2016 18:58
@SuperJMN If you want functionality similar to ViewBox you can try https://www.youtube.com/watch?v=dM_cRdEuksU set AutoFitMode to simulate filling
Control is available to WPF and Avalonia
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:42
Nice!!
I will use it, then!
By the way, I'm having problems to make my UnitTests project work
I'm getting this:
System.IO.FileLoadException: Could not load file or assembly 'System.Reactive.Linq, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:49
If hope somebody could help me. The exception happens when I run the tests
the branch is this one:
@wieslawsoltes can you please run the tests to see if it happens to you?
Steven Kirk
@grokys
Nov 30 2016 20:50
are you using .net standard?
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:51
In OmniXAML, yes
In the Test project, no
Steven Kirk
@grokys
Nov 30 2016 20:51
that'll be your problem (assuming your test project is testing omnixaml)
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:52
yes, it is!
Steven Kirk
@grokys
Nov 30 2016 20:52
i have no idea why it happens but i've seen that too - its part of the reason why we're not on .net standard
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:52
ouh mamma
but I wasn't having any problem until I installed System.ComponentModel.TypeConverter to OmniXAML
Steven Kirk
@grokys
Nov 30 2016 20:53
ha
who knows
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:53
the problem came as soon as I installed that package :S
Steven Kirk
@grokys
Nov 30 2016 20:53
try uninstalling the System.Reactive.Linq package and reinstalling
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:54
I have spent about 2 hours with package restores, reference checking, assembly bindings an s**t like that
Steven Kirk
@grokys
Nov 30 2016 20:54
welcome to the bleeding edge! :)
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:55
you don't know how much I hate when I get the assembly versions don't match
or when the types don't load
2 hours and now I'm about to cry
Steven Kirk
@grokys
Nov 30 2016 20:55
yeah, me too
José Manuel Nieto
@SuperJMN
Nov 30 2016 20:55
I'll come back with a sledgehammer
I'll record everything and post the video to YouTube. At least I'll get famous.
"Coder furiously destroys his workplace with a sledgehammer"