选择Combobox文本时,将光标更改为方形

时间:2016-02-02 19:35:53

标签: c# wpf wpf-controls

我在WPF中有Editable Combobox,它应该工作的方式是,如果文本被选中(突出显示),光标应该变成交叉,这样用户就可以知道他可以将文本移动到另一个Combobox中,如果用户尝试你编辑光标应该是编辑光标。

这是我正在尝试的代码,onFocus Event,

 override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    if let path = tableView.indexPathForSelectedRow {

        tableView.deselectRowAtIndexPath(path, animated: true)
    }
}

这是屏幕截图

enter image description here

在Snap中,自从Austin,TX突出显示以来,我的光标应该交叉!

提前谢谢!

1 个答案:

答案 0 :(得分:0)

使用以下代码:

private void cmb_Loaded(object sender, RoutedEventArgs e)
    {
        TextBox TxtBox = (TextBox)cmb.Template.FindName("PART_EditableTextBox", cmb);
        if (TxtBox != null)
        {
            TxtBox.SelectionChanged += TxtBox_SelectionChanged;
        }
    }

    void TxtBox_SelectionChanged(object sender, RoutedEventArgs e)
    {
        var TxtBox = sender as TextBox;
        if (TxtBox != null && !string.IsNullOrEmpty(TxtBox.SelectedText))
        {
            Mouse.OverrideCursor = Cursors.Cross;
        }
        else
        {
            Mouse.OverrideCursor = Cursors.Arrow;
        }
    }
相关问题