These are chat archives for AvaloniaUI/Avalonia

23rd
Feb 2018
MonkAlex
@MonkAlex
Feb 23 2018 00:31 UTC
What about #1044? Want to run dialog on center of owner =_=
ahopper
@ahopper
Feb 23 2018 07:39 UTC
Hi, in posting about avalonia what link would you like used as the first port of call. I notice both git and avaloniaui.net both still proudly declare it to be in alpha:)
Steven Kirk
@grokys
Feb 23 2018 10:04 UTC
@ahopper i've submitted a PR for the website to fix that
i didn't realize it said we were in alpha that on github. will fix that
MonkAlex
@MonkAlex
Feb 23 2018 10:05 UTC
Has datatemplate with textbox, can i set focus to textbox?
In wpf i use customcontrol with method "focus" in ctor
Steven Kirk
@grokys
Feb 23 2018 10:09 UTC
@MonkAlex initial focus is something that still needs some work. i assume the custom control with Focus in ctor doesn't work?
if not, you could maybe try calling Focus in AttachedToLogicalTree
MonkAlex
@MonkAlex
Feb 23 2018 10:10 UTC
Use datatemplate, no idea how to find ctor :D
Steven Kirk
@grokys
Feb 23 2018 10:11 UTC
use a data template that contains a custom control?
MonkAlex
@MonkAlex
Feb 23 2018 10:11 UTC
Nope. Only datatemplate =(
Steven Kirk
@grokys
Feb 23 2018 10:12 UTC
could you show me some code?
MonkAlex
@MonkAlex
Feb 23 2018 10:12 UTC
Has template -> grid -> textbox:
<DataTemplate DataType="c:SearchViewModel">
<Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*, Auto" DataContext="{Binding}">
<TextBox Grid.Row="0" Grid.Column="0" Text="{Binding Search}"/>
When datacontext changed to SearchViewModel i have no idea, how to set focus on textbox
Steven Kirk
@grokys
Feb 23 2018 10:14 UTC
in WPF can you do it?
MonkAlex
@MonkAlex
Feb 23 2018 10:15 UTC
Nope. In wpf i use customcontrol, and do this.textbox.Focus() in ctor.
Steven Kirk
@grokys
Feb 23 2018 10:15 UTC
yeah so i think you'll need to do the same in avalonia. at least for the moment
or
you could probably actually do something like:
contentControl.Presenter.GetObservable(ContentPresenter.ChildProperty).Subscribe(x => ((Grid)x)?.Children[0].Focus()) or something
(completely untested code)
MonkAlex
@MonkAlex
Feb 23 2018 10:18 UTC
Hm, okay, try test it
Steven Kirk
@grokys
Feb 23 2018 10:18 UTC
i'd like to add a property to auto-focus controls that would handle this, but i've not done it yet
in fact i've wanted to do it so long it's issue number 30! AvaloniaUI/Avalonia#30
MonkAlex
@MonkAlex
Feb 23 2018 11:31 UTC
So, work when i get logical tree
  explorer.Changed
    .Where(c => c.PropertyName == nameof(ExplorerViewModel.SelectedTab))
    .Subscribe(args =>
    {
      var grid = this.LogicalChildren.OfType<Grid>().FirstOrDefault();
      var cp = grid?.GetLogicalChildren().OfType<ContentPresenter>().FirstOrDefault();
      var cpGrid = cp?.GetLogicalChildren().OfType<Grid>().FirstOrDefault();
      var textBox = cpGrid?.GetLogicalChildren().OfType<TextBox>().FirstOrDefault();
      if (textBox != null)
        Dispatcher.UIThread.InvokeAsync(() => textBox.Focus());
    });
Can i do it faster?
MonkAlex
@MonkAlex
Feb 23 2018 11:48 UTC
has avalonia inputbindings analog? Want this
https://stackoverflow.com/a/21110210/3768545
Did not try but it should be possible to bind commands to methods in view model.
MonkAlex
@MonkAlex
Feb 23 2018 11:53 UTC
@wieslawsoltes its work, thanks
ahopper
@ahopper
Feb 23 2018 12:34 UTC
Hi I just put a avalonia version of a small app here https://github.com/ahopper/Patroclus it is a quick and dirty conversion of an already quick and dirty app! The conversion was fairly painless and it works. I'm sure I'm not doing many things the 'avalonia way' but was a useful step to bigger project I want to convert. Thanks to all the developers, it was fun doing it.
danwalmsley
@danwalmsley
Feb 23 2018 12:42 UTC
is the screenshot running there the wpf or avalonia version?
ahopper
@ahopper
Feb 23 2018 12:43 UTC
a very old wpf version, I'll put up a new one
danwalmsley
@danwalmsley
Feb 23 2018 12:43 UTC
id love to see the avalonia screenshot
that looks like a really cool app :)
ahopper
@ahopper
Feb 23 2018 12:44 UTC
it is only the boring foreground window
the long term goal is to convert this http://www.ihopper.org/radio/
kolejium
@kolejium
Feb 23 2018 13:37 UTC
image.png
Hello! Last time, I was a little wrong ... Sorry. Prompt please, I want to make vertical, I found not bad style for WPF.
Vertical TabItem*
<Style TargetType="{x:Type TabItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<ContentPresenter Content="{TemplateBinding Content}">
<ContentPresenter.LayoutTransform>
<RotateTransform Angle="270" />
</ContentPresenter.LayoutTransform>
</ContentPresenter>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="3" />
</Style>
This WPF code
In Avalonia, I try this:
<TabControl.Styles>
<Style Selector="TabItem">
<Setter Property="Header">
<Setter.Value>
<DataTemplate>
<ContentPresenter Content="{TemplateBinding Content}">
<ContentPresenter.RenderTransform>
<RotateTransform Angle="90"/>
</ContentPresenter.RenderTransform>
</ContentPresenter>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Styles>
What am I doing wrong?
I'm still very badly acquainted with Avalonia UI, although I follow the developed for more than a year.
By the way, I still have not found any information for how to work with RenderTransfromOrigin, could you advise me on this?
Sergey Khabibullin
@x2bool
Feb 23 2018 15:15 UTC
image.png
Can't figure out how to bind DropDown.
<DropDown
            Items="{Binding Workspaces}"
            SelectedIndex="{Binding SelectedWorkspaceIndex, Mode=TwoWay}">

            <DropDown.ItemTemplate>
                <DataTemplate>

                    <nav:WorkspaceControl DataContext="{Binding Blah}" />

                </DataTemplate>
            </DropDown.ItemTemplate>

        </DropDown>
It seems that the selected item renders as .ToString of a model object. What's wrong with the binding?
milkinllc
@milkinllc
Feb 23 2018 15:23 UTC
Shouldn't Workspace user control datacontext be bound with {binding} not blah?
Sergey Khabibullin
@x2bool
Feb 23 2018 15:48 UTC
@milkinllc Just tried that and it gives the same result. Blah is just a model that is used later to display text inside WorkspaceControl.
danwalmsley
@danwalmsley
Feb 23 2018 15:57 UTC
@x2bool you shouldn't need to provide the data context
inside the data template
its already set to the datacontext of the selected item for you
Sergey Khabibullin
@x2bool
Feb 23 2018 16:10 UTC

@danwalmsley Just tried that too, same result. Current version:

// workspaces
public IReactiveDerivedList<Model> Workspaces { get; private set; }

// active workspace
private int? _selectedWorkspaceIndex;
public int? SelectedWorkspaceIndex
{
    get => _selectedWorkspaceIndex;
    set => this.RaiseAndSetIfChanged(ref _selectedWorkspaceIndex, value);
}

DropDown:

<DropDown
    Items="{Binding Workspaces}"
    SelectedIndex="{Binding SelectedWorkspaceIndex, Mode=TwoWay}"
    >

    <DropDown.ItemTemplate>
        <DataTemplate>

            <nav:WorkspaceControl />

        </DataTemplate>
    </DropDown.ItemTemplate>

</DropDown>

WorkspaceControl:

<UserControl
    xmlns="https://github.com/avaloniaui"
    >

    <TextBlock Text="{Binding Label}"/>

</UserControl>

Model:

public class Model : ReactiveObject
{   
    private string _label;
    public string Label
    {
        get => _label;
        set => this.RaiseAndSetIfChanged(ref _label, value);
    }
}
danwalmsley
@danwalmsley
Feb 23 2018 16:43 UTC
hmmm i think this might be a bug
I couldnt get it to work just now either!
@grokys @jkoritzinsky @kekekeks Skiasharp 1.6 is out
Jeremy Koritzinsky
@jkoritzinsky
Feb 23 2018 22:02 UTC
They didn't include the native libraries for Linux in this package for whatever reason. I'll open an issue
danwalmsley
@danwalmsley
Feb 23 2018 23:13 UTC
They did post it with the release notes to download separately