feat: respect presenter size change.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<u:Form>
|
||||
<TextBox Width="300" Name="content" u:FormItem.Label="Content" Text="Hello Avalonia"></TextBox>
|
||||
<u:EnumSelector
|
||||
u:FormItem.Label="Direction"
|
||||
Name="direction"
|
||||
@@ -45,8 +46,9 @@
|
||||
Speed="{Binding #speed.Value}"
|
||||
Background="{DynamicResource SemiBlue1}"
|
||||
Direction="{Binding #direction.Value}"
|
||||
Content="{Binding #content.Text}"
|
||||
IsRunning="{Binding #running.IsChecked}">
|
||||
<TextBlock VerticalAlignment="Center" Text="Hello World" />
|
||||
|
||||
</u:Marquee>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Threading;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
@@ -75,6 +76,10 @@ public class Marquee : ContentControl
|
||||
_timer.Elapsed -= TimerOnTick;
|
||||
_timer.Stop();
|
||||
_timer.Dispose();
|
||||
if (Presenter is not null)
|
||||
{
|
||||
Presenter.SizeChanged -= OnPresenterSizeChanged;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,6 +109,22 @@ public class Marquee : ContentControl
|
||||
set => SetValue(SpeedProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
if (Presenter is not null)
|
||||
{
|
||||
Presenter.SizeChanged+= OnPresenterSizeChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPresenterSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
{
|
||||
InvalidatePresenterPosition();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void TimerOnTick(object sender, System.EventArgs e)
|
||||
{
|
||||
var layoutValues = Dispatcher.UIThread.Invoke(GetLayoutValues);
|
||||
|
||||
Reference in New Issue
Block a user