0
我有幾個用戶控件在ListBox中實例化。我在我的窗口中的按鈕這引起了NavigationCommands.Refresh
和CanExecute
處理程序,以允許它執行:隧道命令
<Window.CommandBindings>
<CommandBinding Command="NavigationCommands.Refresh" CanExecute="CanAlwaysExecute" />
</Window.CommandBindings>
在這些動態創建的用戶控件(列表框的ItemTemplate內創建的),我有NavigationCommands.Refresh
的處理程序。當我點擊窗口中的按鈕時,是否應該在每個usercontrols中設置的處理程序不會觸發?我需要命令來挖掘每個UC,但事實並非如此。
<UserControl.CommandBindings>
<CommandBinding Command="NavigationCommands.Refresh" Executed="UpdateStatus" CanExecute="CanAlwaysExecute" />
</UserControl.CommandBindings>
....
<Button Width="200" Text="Refresh All" Command="NavigationCommands.Refresh"/>
那麼我會如何實現呢? – Echilon
@Echilon:有創意。例如如果單擊主按鈕,則手動爲所有感興趣的控件提起命令。 –
這將需要遍歷列表框中的所有控件,找到嵌套在其中的另一個ListBox,然後循環遍歷所有項目並找到我的用戶控件,然後調用一個方法。有沒有更優雅的方式? – Echilon