Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:35
    timunie closed #10225
  • 15:34
    timunie commented #10225
  • 15:28
    tivewsalaeharad commented #10225
  • 15:28
    tivewsalaeharad commented #10225
  • 14:12
    timunie commented #10225
  • 13:54
    jp2masa commented #10225
  • 13:36
    jp2masa labeled #10226
  • 13:36
    jp2masa opened #10226
  • 12:50
    Stannieman commented #8894
  • 12:46
    tivewsalaeharad labeled #10225
  • 12:46
    tivewsalaeharad opened #10225
  • 11:57
    avaloniaui-team commented #10224
  • 11:55
    affederaffe synchronize #9810
  • 11:19
    MrJul opened #10224
  • 11:06
    navhaxs commented #9989
  • 11:05
    navhaxs commented #9989
  • 09:28
    avaloniaui-team commented #10222
  • 09:03
    jp2masa opened #10222
  • 08:16
    jp2masa ready_for_review #10210
  • 07:08
    maxkatz6 closed #10122
.
@avaloniaui:matrix.org
[m]
Bunny
Same when I debugging autocomplete lol

timunie
Robert I found that I can disable parent key bindings if I place another one inside TextBox like:

<Window.KeyBindings>
    <KeyBinding Command="{Binding DoSometingCommand}" Gesture="Ctrl+C"></KeyBinding>
</Window.KeyBindings>
<Design.DataContext>
    <vm:MainWindowViewModel/>
</Design.DataContext>
<StackPanel>
    <TextBox>
        <TextBox.KeyBindings>
            <KeyBinding Command="{Binding DoNothingCommand}" Gesture="Ctrl+C"></KeyBinding>
        </TextBox.KeyBindings>
    </TextBox>
    <TextBlock Text="{Binding Count}"></TextBlock>
    <Button />
</StackPanel>

my ViewModel:
```
public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty]
private int _Count;
[RelayCommand]
void DoSometing() => Count++;

[RelayCommand]
void DoNothing(){}

}
``` (re @Robert: @timunie looks like there is no way to capture key events before KeyBindings are fired
https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Input/KeyboardDevice.cs#L229
It walks up the visual tree, checks every element for bindings and only after that the event is actually raised to the source)

.
@avaloniaui:matrix.org
[m]
木南
hi everyone ,who can help me with this issue
timunie
I think it needs some time
timunie
@Gillibald already assigned it to himself, so I think he'll try to fix it
timunie
But as usual in Open Source, there is no due date we can conform I think
木南
ok,thanks
Cole Tobin
@colejohnson66

Hi. Got a problem with bindings for templated controls.

My control uses a check box:

<CheckBox
    Classes="OptionTitle"
    Content="{TemplateBinding Title}"
    IsChecked="{TemplateBinding ShowOption}" />

with the property declared in the backing code as:

public static readonly StyledProperty<bool> ShowOptionProperty =
    AvaloniaProperty.Register<OptionTitle, bool>(nameof(ShowOption));
public bool ShowOption
{
    get => GetValue(ShowOptionProperty);
    set => SetValue(ShowOptionProperty, value);
}

However, my binding is not receiving update notifications:

<controls:OptionTitle
    ShowOption="{CompiledBinding ShowOptionX}"
    Title="X" />

this.WhenAnyValue(vm => vm.ShowOptionX).Subscribe(_ => ...); never fires.

If, in my VM constructor, I do ShowOptionX = true;, the WhenAnyValue observable fires just the once, but never again.

Any ideas what I'm doing wrong?

.
@avaloniaui:matrix.org
[m]
timunie
Show your VM
timunie
ShowOptionX
timunie
wait,
timunie
try IsChecked="{TemplateBinding ShowOption, Mode=TwoWay}
Cole Tobin
@colejohnson66
It's a reactive property:
    private bool _showOptionX;
    public bool ShowOptionX
    {
        get => _showOptionX;
        set => this.RaiseAndSetIfChanged(ref _showOptionX, value);
    }
Two way didn't fix it. It still doesn't fire.
.
@avaloniaui:matrix.org
[m]
timunie
Are you inheriting a UserControl
Cole Tobin
@colejohnson66
I'm using what Rider gave me when I asked for a templated control file: public class OptionTitle : TemplatedControl
.
@avaloniaui:matrix.org
[m]
timunie
that's right
timunie
Are you sure your VM is set?
timunie
Use CompiledBindings if you are not doing so
Cole Tobin
@colejohnson66
I GOT IT
.
@avaloniaui:matrix.org
[m]
timunie
If you have still issues, we need a sample
Cole Tobin
@colejohnson66
I had to use Mode=TwoWay on the actual compiled bindings
.
@avaloniaui:matrix.org
[m]
timunie
what was wrong?
Cole Tobin
@colejohnson66
in addition to inside the control
.
@avaloniaui:matrix.org
[m]
timunie
But you can also make twoway default in StylesProperty
timunie
I don't rembmer the sytax
timunie
In Register I think
Cole Tobin
@colejohnson66
AvaloniaProperty.Register<OptionTitle, bool>(nameof(ShowOption), defaultBindingMode: BindingMode.TwoWay);
It's good now. Thanks for suggesting the binding mode earlier!
I always forget about that
.
@avaloniaui:matrix.org
[m]

Robert
Thanks, I gave this a shot but it was still preventing the textbox from receiving input when I tried it. In any case I solved it now by making the commands unexecutable when that textbox is active. Not ideal and only works for my situation, but atleast it works around my impedement (re @timunie: Robert I found that I can disable parent key bindings if I place another one inside TextBox like:

<Window.KeyBindings>
<KeyBinding Command="{Binding DoSometingCommand}" Gesture="Ctrl+C"></KeyBinding>
</Window.KeyBindings>

<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>

<StackPanel>
<TextBox>
<TextBox.KeyBindings>
<KeyBinding Command="{Binding DoNothingCommand}" Gesture="Ctrl+C"></KeyBinding>
</TextBox.KeyBindings>
</TextBox>
<TextBlock Text="{Binding Count}"></TextBlock>
<Button />
</StackPanel>
my ViewModel:
public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty]
private int _Count;
[RelayCommand]
void DoSometing() => Count++;

[RelayCommand]
void DoNothing(){}

})

Robert
It did prevent the other events from triggering so that did work ^^
.
@avaloniaui:matrix.org
[m]
RazorSharpFang
I don't think I'm going to find a solution to the issue I found earlier. It really looks like without the collection class implementing non-generic IList that there's no good solutions to indexing a collection by integer index that works with both classes and structs being enumerated.
RazorSharpFang
You just have to implement non-generic IList, even if you have all of the mutating methods throw exceptions.
.
@avaloniaui:matrix.org
[m]
timunie
Yeah I made a DoNothingCommand. This can also be a DoSomethingElseCommand where you provide a CommandParameter. But as you now have a solution, I think it's okay. (re @Robert: It did prevent the other events from triggering so that did work ^^)
timunie
I'm not sure if we need a way to support this somehow. So proably worth to open a feature request where this can be discussed further.
timunie
As I wrote in your ticket, also M$ did it that way. So I think it's not Avalonias fault. Anyway, all the Devs I asked agreed with your findings. It just feels like that supporting the interface is a rare case and not worth the pain. (re @RazorSharpFang: You just have to implement non-generic IList, even if you have all of the mutating methods throw exceptions.)
timunie
Just my 2 cents, not a final judgement
.
@avaloniaui:matrix.org
[m]
RazorSharpFang
It looks really difficult to do this without having the Type to be indexed also specified - which has really big implications for the inheritance hierarchy of the classes in question.
I don't know if it's unreasonable to ask for the type to be displayed specified? But that has implications for the IDataTemplate implementors.
🤷‍♂️ (re @timunie: Just my 2 cents, not a final judgement)
RazorSharpFang
Nothing I am able to think of I like.
.
@avaloniaui:matrix.org
[m]
.
@avaloniaui:matrix.org
[m]
RazorSharpFang
Yea 😭
Nothing to do, but implement IList and add a lot of throw statements.
.
@avaloniaui:matrix.org
[m]
Bunny
Do we have a convenient way to apply TextDecorations to all text elements in ContentPresenter?
timunie
Via Styles ?
timunie
You can apply them globally in App.axaml or locally in each node
.
@avaloniaui:matrix.org
[m]
:point_up: Edit: timunie
I'm not sure if we need a way to support this somehow. So proably worth to open a feature request where this can be discussed further.
.
@avaloniaui:matrix.org
[m]
Bunny
Thanks, I want to apply that in a control theme, but with a property as selector to determine whether the decoration should be applied. It's kind hard to implement with style selector. Not really specific to TextDecoration.
Bunny