mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Add main view model binding
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
xmlns:ToolkitBehaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
|
xmlns:ToolkitBehaviors="using:Microsoft.Toolkit.Uwp.UI.Animations.Behaviors"
|
||||||
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:Behaviors="using:PowerToysUX.Behaviours"
|
|
||||||
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
|
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
|
||||||
d:DesignHeight="300"
|
d:DesignHeight="300"
|
||||||
d:DesignWidth="400">
|
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">
|
<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>
|
<AutoSuggestBox.QueryIcon>
|
||||||
<SymbolIcon Symbol="Find"/>
|
<SymbolIcon Symbol="Find"/>
|
||||||
</AutoSuggestBox.QueryIcon>
|
</AutoSuggestBox.QueryIcon>
|
||||||
|
|||||||
@@ -168,19 +168,19 @@ namespace PowerLauncher
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private void UpdatePosition()
|
private void UpdatePosition()
|
||||||
//{
|
{
|
||||||
// if (_settings.RememberLastLaunchLocation)
|
if (_settings.RememberLastLaunchLocation)
|
||||||
// {
|
{
|
||||||
// Left = _settings.WindowLeft;
|
Left = _settings.WindowLeft;
|
||||||
// Top = _settings.WindowTop;
|
Top = _settings.WindowTop;
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// Left = WindowLeft();
|
Left = WindowLeft();
|
||||||
// Top = WindowTop();
|
//Top = WindowTop();
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
private void OnLocationChanged(object sender, EventArgs e)
|
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.
|
if (sender == null) return;
|
||||||
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;
|
|
||||||
|
|
||||||
|
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