These are chat archives for AvaloniaUI/Avalonia

27th
Aug 2016
Darnell Williams
@Seeker1437
Aug 27 2016 02:47
@kekekeks finally got the vm up lol
I went and bought a full windows license to get it installed. However I messed up... I wanted to use my usb drive to boot the vm now the vm won't boot unless the USB drive is attached.
I really don't want to reinstall :(
Nikita Tsukanov
@kekekeks
Aug 27 2016 07:51
You know, you could download a pre-installed image and then activate it with your key
Mathias Fischler
@Mafii
Aug 27 2016 09:15
hey, is there a way to access the root control of a usercontrol and dynamically add controls to it?
from code behind
Nikita Tsukanov
@kekekeks
Aug 27 2016 11:06
There was ancestorfinder class
That provides you with observable
that gives you parent control of specified type
So, basically, you need to construct one with typeof(TopLevel) as an argument
And subscribe to returned observable
Mathias Fischler
@Mafii
Aug 27 2016 11:14
@kekekeks thank you very much :)
Steven Kirk
@grokys
Aug 27 2016 14:30
@Mafii if you don't need to track it dynamically just use control.GetLogicalAncestors().OfType<TopLevel>().First()
Andrew
@zezba9000
Aug 27 2016 18:35
@grokys Yes I have already used the Image example. I'm doing this programmatically and using binding NOT setting the Source via XAML.
Andrew
@zezba9000
Aug 27 2016 19:16
Setting image source in XAML works fine like so:
<UserControl.DataTemplates>
        <DataTemplate DataType="self:FileItem">
            <StackPanel Orientation="Horizontal">
<!--Does work--->
                <Image Source="resm:GitItGUI.Icons.AppIcon.png?assembly=GitItGUI" Width="24" Height="24"/>
                <TextBlock Text="{Binding Filename}" VerticalAlignment="Center">
                    <TextBlock.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Open file"/>
                            <MenuItem Header="Open file location"/>
                            <MenuItem Header="Revert file"/>
                        </ContextMenu>
                    </TextBlock.ContextMenu>
                </TextBlock>
            </StackPanel>
        </DataTemplate>
    </UserControl.DataTemplates>
Binding does NOT work:
<UserControl.DataTemplates>
        <DataTemplate DataType="self:FileItem">
            <StackPanel Orientation="Horizontal">
<!--Doesn't work--->
                <Image Source="{Binding Icon}" Width="24" Height="24"/>
                <TextBlock Text="{Binding Filename}" VerticalAlignment="Center">
                    <TextBlock.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Open file"/>
                            <MenuItem Header="Open file location"/>
                            <MenuItem Header="Revert file"/>
                        </ContextMenu>
                    </TextBlock.ContextMenu>
                </TextBlock>
            </StackPanel>
        </DataTemplate>
    </UserControl.DataTemplates>
(Binding Filename} does work fine
{Binding Icon} does not
Icon is loaded in code like so:
icon = new Image();
            icon.BeginInit();
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            using (var stream = assembly.GetManifestResourceStream(iconFilename))
            {
                icon.Source = new Bitmap(stream);
            }
            icon.EndInit();
Is there some method that needs to be called after Image.Source is set in C#?
Andrew
@zezba9000
Aug 27 2016 19:29
face palm... aww sorry I had bound a Image.Source to a Image not a Bitmap... grr, sorry
And I see I can load an image via: AvaloniaLocator.Current.GetService<IAssetLoader>().Open(new Uri(filename)) as well
Steven Kirk
@grokys
Aug 27 2016 20:16
You can just pass the filename in the bitmap constructor too
danwalmsley
@danwalmsley
Aug 27 2016 20:36
@grokys I'm trying to add unit tests for certain parts of Avalon Studio... but I need to get the Dispatcher.UIThread to process its queue manually in the test, is this possible?
Dispatcher.UIThread.RunJobs();
I suspect this might do it
danwalmsley
@danwalmsley
Aug 27 2016 20:48
hmmm seems like I need to get dispatcher to initialise first...
Steven Kirk
@grokys
Aug 27 2016 21:08
@danwalmsley we don't really have a good story for unit testing dispatcher/timer etc stuff
we need to be able to swap out the implementation for a mock which would allow testing
Nikita Tsukanov
@kekekeks
Aug 27 2016 21:09
One can substitute IPlatformThreadingInterface
Steven Kirk
@grokys
Aug 27 2016 21:11
ah cool so that can be mocked. not got the code to hand atm to check
Nikita Tsukanov
@kekekeks
Aug 27 2016 21:15
BTW, there is Dispatcher::RunJobs method
But it needs to have IPlatformThreadingInterface registered first
danwalmsley
@danwalmsley
Aug 27 2016 21:37
I tried doing this at beginning of test...
Task.Factory.StartNew(() =>
            {
                Dispatcher.UIThread.MainLoop(new CancellationToken());
            });
but give some kind of null reference exception, cant tell what the source is
Steven Kirk
@grokys
Aug 27 2016 21:45
how come you can't tell what the source is? if you debug the unit test it should break on the line
there's also a UnitTestApplication that's used to set up services, look at other tests to see how they're done
you can use that and mock your own IPlatformThreadingInterface
sorry i can't give more info, still on holiday, get back monday
danwalmsley
@danwalmsley
Aug 27 2016 21:47
thanks mate
Weston
@ronnyek
Aug 27 2016 23:12
@kekekeks what are the dependencies that need to be ported to netcore to be able to support avaloinia