簡體   English   中英

RadListBox 與 RadListBoxItem DragDrop WPF

[英]RadListBox vs RadListBoxItem DragDrop WPF

我正在使用Telerik控件開發具有MVVM模式的WPF應用程序。

我正在使用telerik:RadListBox ,為其綁定了一個集合。 我的問題是,當集合綁定到 RadListBox 時,該集合將變成RadListBoxRadListBoxItem嗎?

XAML:

<telerik:RadListBox x:Name="lstMarketSeries" ItemsSource="{Binding MarketSeriesCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, ValidatesOnDataErrors=True}" ItemContainerStyle="{StaticResource DraggableListBoxItem}"DragLeave="lstMarketSeries_DragLeave" Style="{StaticResource myListboxStyle}" SelectionMode="Extended" telerik:StyleManager.Theme="Windows8">
</telerik:RadListBox>

XAML.cs:

/// <summary>
/// Event fired when series are dragged and moved.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lstMarketSeries_DragLeave(object sender, DragEventArgs e)
{

   if (sender is RadListBox) // True
    {

    }

   if(sender is RadListBoxItem) //False Why??
    {

    }
}

當一個集合被綁定時,它應該作為 Items Correct 返回嗎? 為什么我得到它作為RadListBox本身而不是RadListBoxItem

現在我需要那個 Draggable 對象作為RadListBoxItem 有什么辦法嗎?

僅供參考,

看這里ListBoxDragDrop發件人是ListBoxItem而不是ListBox

請參閱文檔

發件人是

附加事件處理程序的對象。

就是這樣。

您正在拖動一個項目,但該事件已附加到容器。

<telerik:RadListBox ... DragLeave="lstMarketSeries_DragLeave" ... >`

Therfore當DragLeave事件發生到RadListBox,指定的處理程序被觸發(這實際上是由您定)。 sender設置為RadListBox因為處理程序附加到它,而不是項目。

您誤解了您所指的示例。 仔細閱讀示例代碼。 在示例中,事件處理程序設置為ItemContainerStyle它用於膨脹每個項目 在示例中,我們看到處理程序單獨附加到每個項目,因此處理程序的sender設置為項目而不是控件本身。

如果你需要sender來定義一個項目,你必須做同樣的事情 - 創建一個樣式並為其附加一個處理程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM