mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
feat: ShortcutDialog 支持 _IsError 属性用于绑定
This commit is contained in:
parent
8d112b21bd
commit
2df8d76cf4
9 changed files with 75 additions and 29 deletions
|
|
@ -10,6 +10,13 @@ using namespace Windows::UI::Xaml::Controls;
|
|||
|
||||
namespace winrt::Magpie::App::implementation {
|
||||
|
||||
const DependencyProperty ShortcutControl::_IsErrorProperty = DependencyProperty::Register(
|
||||
L"_IsError",
|
||||
xaml_typename<bool>(),
|
||||
xaml_typename<Magpie::App::ShortcutControl>(),
|
||||
PropertyMetadata(box_value(false), &ShortcutControl::_OnIsErrorChanged)
|
||||
);
|
||||
|
||||
ShortcutControl* ShortcutControl::_that = nullptr;
|
||||
|
||||
ShortcutControl::ShortcutControl() {
|
||||
|
|
@ -62,9 +69,18 @@ void ShortcutControl::ShortcutDialog_Closing(ContentDialog const&, ContentDialog
|
|||
if (args.Result() == ContentDialogResult::Primary) {
|
||||
_hotkey.CopyFrom(_previewHotkey);
|
||||
KeysControl().ItemsSource(_hotkey.GetKeyList());
|
||||
_propertyChangedEvent(*this, PropertyChangedEventArgs{ L"IsError" });
|
||||
}
|
||||
}
|
||||
|
||||
void ShortcutControl::_IsError(bool value) {
|
||||
SetValue(_IsErrorProperty, box_value(value));
|
||||
}
|
||||
|
||||
bool ShortcutControl::IsError() const {
|
||||
return GetValue(_IsErrorProperty).as<bool>();
|
||||
}
|
||||
|
||||
bool CheckVirtualKey(DWORD vkCode) {
|
||||
return (vkCode >= 'A' && vkCode <= 'Z') // 字母
|
||||
|| (vkCode >= '0' && vkCode <= '9') // 数字(顶部)
|
||||
|
|
@ -83,6 +99,14 @@ bool CheckVirtualKey(DWORD vkCode) {
|
|||
|| vkCode == VK_RETURN; // 回车
|
||||
}
|
||||
|
||||
event_token ShortcutControl::PropertyChanged(Data::PropertyChangedEventHandler const& value) {
|
||||
return _propertyChangedEvent.add(value);
|
||||
}
|
||||
|
||||
void ShortcutControl::PropertyChanged(event_token const& token) {
|
||||
_propertyChangedEvent.remove(token);
|
||||
}
|
||||
|
||||
LRESULT ShortcutControl::_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
||||
if (nCode != HC_ACTION || !_that) {
|
||||
return CallNextHookEx(NULL, nCode, wParam, lParam);
|
||||
|
|
@ -179,4 +203,9 @@ LRESULT ShortcutControl::_LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM
|
|||
return -1;
|
||||
}
|
||||
|
||||
void ShortcutControl::_OnIsErrorChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&) {
|
||||
ShortcutControl* that = get_self<ShortcutControl>(sender.as<default_interface<ShortcutControl>>());
|
||||
that->_propertyChangedEvent(*that, PropertyChangedEventArgs{ L"IsError" });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue