mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Add main view model binding
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
mc:Ignorable="d"
|
||||
xmlns:ToolkitBehaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
|
||||
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:Behaviors="using:PowerToysUX.Behaviours"
|
||||
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
d:DesignHeight="300"
|
||||
d:DesignWidth="400">
|
||||
@@ -418,7 +417,7 @@
|
||||
<Grid x:Name="PowerBar" CornerRadius="4" Height="72" Background="{StaticResource BackdropAcrylicBrush}" Translation="0,0,16" Shadow="{StaticResource ShellBarShadow}" Margin="12" VerticalAlignment="Top" HorizontalAlignment="Center" MinWidth="240">
|
||||
|
||||
|
||||
<AutoSuggestBox x:Name="SearchBox" PlaceholderText="Launch an app" FontSize="24" Style="{StaticResource CustomStyledAutoSuggestBox}" TextChanged="SearchBox_TextChanged" MinWidth="720" >
|
||||
<AutoSuggestBox x:Name="SearchBox" x:FieldModifier="public" PlaceholderText="Launch an app" FontSize="24" Style="{StaticResource CustomStyledAutoSuggestBox}" TextChanged="SearchBox_TextChanged" MinWidth="720" >
|
||||
<AutoSuggestBox.QueryIcon>
|
||||
<SymbolIcon Symbol="Find"/>
|
||||
</AutoSuggestBox.QueryIcon>
|
||||
|
||||
@@ -168,19 +168,19 @@ namespace PowerLauncher
|
||||
}
|
||||
}
|
||||
|
||||
//private void UpdatePosition()
|
||||
//{
|
||||
// if (_settings.RememberLastLaunchLocation)
|
||||
// {
|
||||
// Left = _settings.WindowLeft;
|
||||
// Top = _settings.WindowTop;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Left = WindowLeft();
|
||||
// Top = WindowTop();
|
||||
// }
|
||||
//}
|
||||
private void UpdatePosition()
|
||||
{
|
||||
if (_settings.RememberLastLaunchLocation)
|
||||
{
|
||||
Left = _settings.WindowLeft;
|
||||
Top = _settings.WindowTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
Left = WindowLeft();
|
||||
//Top = WindowTop();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLocationChanged(object sender, EventArgs e)
|
||||
{
|
||||
@@ -246,14 +246,42 @@ namespace PowerLauncher
|
||||
// }
|
||||
//}
|
||||
|
||||
private void WindowsXamlHost_ChildChanged(object sender, EventArgs e)
|
||||
private PowerLauncher.UI.LauncherControl _launcher = null;
|
||||
private void WindowsXamlHost_ChildChanged(object sender, EventArgs ev)
|
||||
{
|
||||
// Hook up x:Bind source.
|
||||
global::Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost windowsXamlHost =
|
||||
sender as global::Microsoft.Toolkit.Wpf.UI.XamlHost.WindowsXamlHost;
|
||||
global::PowerLauncher.UI.LauncherControl userControl =
|
||||
windowsXamlHost.GetUwpInternalObject() as global::PowerLauncher.UI.LauncherControl;
|
||||
if (sender == null) return;
|
||||
|
||||
var host = (WindowsXamlHost)sender;
|
||||
_launcher = (PowerLauncher.UI.LauncherControl)host.Child;
|
||||
_launcher.DataContext = _viewModel;
|
||||
_launcher.SearchBox.TextChanged += QueryTextBox_TextChanged;
|
||||
|
||||
_launcher.SearchBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
|
||||
|
||||
_viewModel.PropertyChanged += (o, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(MainViewModel.MainWindowVisibility))
|
||||
{
|
||||
if (Visibility == System.Windows.Visibility.Visible)
|
||||
{
|
||||
Activate();
|
||||
_launcher.SearchBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
|
||||
UpdatePosition();
|
||||
_settings.ActivateTimes++;
|
||||
if (!_viewModel.LastQuerySelected)
|
||||
{
|
||||
_viewModel.LastQuerySelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
private void QueryTextBox_TextChanged(Windows.UI.Xaml.Controls.AutoSuggestBox sender, Windows.UI.Xaml.Controls.AutoSuggestBoxTextChangedEventArgs args)
|
||||
{
|
||||
if (_viewModel.QueryTextCursorMovedToEnd)
|
||||
{
|
||||
_viewModel.QueryTextCursorMovedToEnd = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user