我正在使用第三方查找和替换wpf控件。因此,当我按下CTRL + F时,弹出窗口应显示为“IsOpen
”属性,此处为代码:
然后它应该改变值,但不是:
我并不总是看到这种行为,但是当我在页面之间导航时,它会以正确的方式停止工作。
编辑:尝试使用SetCurrentValue
,结果是一样的:
编辑2:这是属性更改回调
static void IsOpenPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
RapidFindReplacePopupControl pop = sender as RapidFindReplacePopupControl;
if (pop.PART_RapidFindReplaceControl != null && pop.PART_RapidFindReplaceControl.PART_FindTextBox != null)
{
pop.PART_RapidFindReplaceControl.PART_FindTextBox.Focus();
if(pop._PART_RapidFindReplaceControl.FindOptions.FindAsYouType)
pop.PART_RapidFindReplaceControl.ViewModel.FindTextCommand.Execute(null);
}
}
}
EDIT3:这是'IsOpen'属性的用法,只在代码中设置/获取,没有任何绑定:
我发现'IsOpenProperty'本身参与绑定:
public override void OnApplyTemplate()
{
...
BindingOperations.SetBinding(this, RapidFindReplacePopupControl.IsOpenProperty, new Binding { Source = PART_Popup, Path = new PropertyPath("IsOpen"), Mode = BindingMode.TwoWay });
...
}
经过一些研究后我发现问题在于使用内置ApplicationCommamnds.Find
而不是它我尝试简单的按钮事件处理程序
private void OutlineTextBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.F &&
e.KeyboardDevice.IsKeyDown(Key.LeftCtrl))
e.Handled = true;
ShowFindAndReplacePopUp();
}
private void ShowFindAndReplacePopUp()
{
FindReplacePopup.IsOpen = true;
}
它很好用。