我有RibbonApplicationMenu在我的應用程序類似於此示例:不同的行爲命令
<RibbonApplicationMenu>
<RibbonApplicationMenuItem Header="Open Project..." Command="{Binding OpenProjectCommand}" />
<RibbonApplicationMenuItem Header="Save Project..." Command="{Binding SaveProjectCommand}" />
<RibbonApplicationMenuItem Header="Exit" Command="{Binding CloseWindowCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type RibbonWindow}}}" />
<RibbonApplicationMenu.FooterPaneContent>
<RibbonButton Label="Exit" Command="{Binding CloseWindowCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type RibbonWindow}}}" />
</RibbonApplicationMenu.FooterPaneContent>
</RibbonApplicationMenu>
private void CloseWindow (Object parameter)
{
((Window) parameter).Close();
}
在該例子中存在具有通過相同的參數綁定到相同的命令和RibbonApplicationMenuItem項RibbonButton和。該命令執行CloseWindow()函數。我感到好奇的是,當單擊RibbonApplicationMenuItem時,該函數的參數是指向RibbonWindow的指針。但是,單擊RibbonButton時,該函數的參數爲空。
爲什麼行爲會有所不同?
會是什麼把一個關閉按鈕在頁腳的正常方式? –
我想說第二個選項。 (對不起,延遲!) – Dusan
第二個選項解決了我的問題。奇怪的是,即使它找不到我的CloseWindowCommand,我在Output窗口中也沒有綁定錯誤。 –