One-time binding for main window width

This commit is contained in:
Yusyuriv 2024-05-28 13:54:30 +06:00
parent b87237fd6c
commit 52d142cb16
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
2 changed files with 3 additions and 11 deletions

View file

@ -12,7 +12,7 @@
xmlns:vm="clr-namespace:Flow.Launcher.ViewModel"
Name="FlowMainWindow"
Title="Flow Launcher"
Width="{Binding MainWindowWidth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Width="{Binding MainWindowWidth, Mode=OneTime}"
MinWidth="400"
MinHeight="30"
d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
@ -30,7 +30,6 @@
PreviewKeyUp="OnKeyUp"
ResizeMode="CanResize"
ShowInTaskbar="False"
SizeChanged="Window_SizeChanged"
SizeToContent="Height"
Topmost="True"
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

View file

@ -45,7 +45,6 @@ namespace Flow.Launcher
private MainViewModel _viewModel;
private bool _animating;
private bool isArrowKeyPressed = false;
private double WindowWidthForSave;
private MediaPlayer animationSoundWMP;
private SoundPlayer animationSoundWPF;
@ -121,6 +120,8 @@ namespace Flow.Launcher
_settings.MaxResultsToShow = Convert.ToInt32(Math.Truncate(itemCount));
}
}
_viewModel.MainWindowWidth = Width;
FlowMainWindow.SizeToContent = SizeToContent.Height;
}
@ -154,9 +155,6 @@ namespace Flow.Launcher
private async void OnClosing(object sender, CancelEventArgs e)
{
_notifyIcon.Visible = false;
/* In this timing, window alreayd closed and it effect to window size. So at this point, whenever the window changes,
we recall the width we've stored as a variable and specify it in the settings. This way, the existing window size will be recalled on the next run.*/
_settings.WindowSize = WindowWidthForSave;
App.API.SaveAppAllSettings();
e.Cancel = true;
await PluginManager.DisposePluginsAsync();
@ -834,10 +832,5 @@ namespace Flow.Launcher
be.UpdateSource();
}
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
WindowWidthForSave = Width;
}
}
}