refactor: move binding for ToolTip.IsOpen from code to axaml

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-14 11:51:40 +08:00
parent 0cb2ca78fe
commit e7f0217a7b
No known key found for this signature in database
2 changed files with 7 additions and 17 deletions

View file

@ -203,6 +203,13 @@
FullMessage="{Binding #ThisControl.FullMessage}"
HorizontalAlignment="Stretch"
TextWrapping="Wrap">
<ToolTip.IsOpen>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="$self.IsPointerOver"/>
<Binding Path="$self.(ToolTip.Tip)" Converter="{x:Static ObjectConverters.IsNotNull}"/>
</MultiBinding>
</ToolTip.IsOpen>
<v:CommitMessagePresenter.DataTemplates>
<DataTemplate DataType="m:Commit">
<StackPanel MinWidth="400" Orientation="Vertical">

View file

@ -5,8 +5,6 @@ using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Input;
using Avalonia.Threading;
using Avalonia.VisualTree;
@ -26,21 +24,6 @@ namespace SourceGit.Views
protected override Type StyleKeyOverride => typeof(SelectableTextBlock);
public CommitMessagePresenter()
{
var bindings = new MultiBinding()
{
Converter = BoolConverters.And,
Bindings = new[]
{
new Binding() { Path = "IsPointerOver", Source = this },
new Binding() { Path = "(ToolTip.Tip)", Source = this, TypeResolver = (_, name) => name == "ToolTip" ? typeof(ToolTip) : null, Converter = ObjectConverters.IsNotNull },
}
};
Bind(ToolTip.IsOpenProperty, bindings);
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);