如果我在TreeViewItem上處理PreviewMouseDown事件,那麼我會點擊TreeViewItem的左側(Windows XP)包含的小+/-框來獲取事件。我如何區分這一點?TreeViewItem上的WPF TreeView PreviewMouseDown
我試過如下:
// We've had a single click on a tree view item
// Unfortunately this is the WHOLE tree item, including the +/-
// symbol to the left. The tree doesn't do a selection, so we
// have to filter this out...
MouseDevice device = e.Device as MouseDevice;
// This is bad. The whole point of WPF is for the code
// not to know what the UI has - yet here we are testing for
// it as a workaround. Sigh...
// This is broken - if you click on the +/- on a item, it shouldn't
// go on to be processed by OnTreeSingleClick... ho hum!
if (device.DirectlyOver.GetType() != typeof(Path))
{
OnTreeSingleClick(sender);
}
我後是不包括它似乎包括額外的比特樹型視圖項目只是單一的點擊。
我在找的是一種檢測是否點擊了TreeViewItem左邊的+/-按鈕的方法。我所看到的是邊界或路徑。不幸的是,如果你點擊文本塊外的文本塊,你會得到一個邊界。所以我無法區分點擊TreeViewItem或+/-。我看到的唯一的獨特之處是Path - 但是,如果我在TreeViewItem中使用Path項,我該如何區分它們? – imekon 2010-06-02 08:42:56
也許設置任何你放在TreeViewItem的「內容」的東西的標籤屬性,以區別於其他東西? – JustABill 2010-06-02 15:09:51