久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

右鍵單擊 Silverlight 4 應用程序中的列表框

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應用程序中的列表框)
本文介紹了右鍵單擊 Silverlight 4 應用程序中的列表框的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試實現(xiàn)我過去在 Winforms 應用程序中認為理所當然的內(nèi)容.我是 Silverlight 菜鳥,所以希望所有這些都是初級的.

I am trying to implement what I used to take for granted in Winforms applications. I am a Silverlight noob, so hopefully all this is elementary.

我在 Silverlight 4 應用中有一個列表框.我想執(zhí)行以下操作:

I have a listbox in a Silverlight 4 app. I'd like to do the following:

  1. 右鍵單擊列表框
  2. 將項目放在我點擊突出顯示的位置
  3. 我想要彈出一個上下文菜單(在上下文菜單中有我自己的項目)

從我目前的研究來看,Silverlight 中似乎沒有 ContextMenu 構(gòu)造,相反,我們必須構(gòu)建一個 Grid/Canvas 結(jié)構(gòu)并將其附加到一個 Popup 對象,然后彈出該對象.

From my research so far, it appears that there is no ContextMenu construct in Silverlight, instead we have to build up a Grid/Canvas structure and attach it to a Popup object, which is what is then popped up.

我的問題如下:

  1. 要完成 #2,我需要對列表框進行某種命中測試.我不知道該怎么做,我的 google-fu 也沒有幫助.
  2. 一旦我確定了鼠標下的索引,我該如何實際選擇項目?
  3. 是否有我可以使用的可重用上下文菜單組件?如果組件允許任意子菜單,則額外加分.

推薦答案

我一直在尋找同樣的事情.我在 CodePlex 檢查了 Silverlight Control Toolkit 并瀏覽了示例(這是一個非常方便的資源),這就是我發(fā)現(xiàn)是您所問問題的解決方案:

I've been looking around for the same thing. I checked the Silverlight Control Toolkit at CodePlex and went through the samples (it's a very handy resource) and here's what I found to be the solution to what you asked:

  1. 為您的列表框創(chuàng)建一個 ItemTemplate

  1. Create an ItemTemplate for your ListBox

在您希望成為可右鍵單擊"的 ItemTemplate 的部分中,設置 System.Windows.Controls.Input 中存在的附加屬性 ContextMenuService.ContextMenu.Toolkit 命名空間

in the part that you want to be "right-clickable" of your ItemTemplate set the attached property ContextMenuService.ContextMenu that exists within the System.Windows.Controls.Input.Toolkit namespace

將 MenuItem 控件添加到您的 ContextMenu 并將 Click 屬性設置為相應的點擊事件處理程序

add MenuItem controls to your ContextMenu and set the Click property to the corresponding click event handler

在事件處理程序中,從發(fā)送方獲取DataContext(您可以使用它在ListBox中找到相應的元素)

in the event handler, get the DataContext from the sender (you can use that to find the corresponding element in the ListBox)

要使該元素被選中,只需將列表框中的 SelectedItem 屬性設置為它

to make that element Selected, just set the SelectedItem property in the list box to it

向事件處理程序添加任何自定義邏輯

Add any custom logic to the event handler

示例頁面中有一個示例,只需從導航窗格中轉(zhuǎn)到Input->ContextMenu"即可.

There's an example in the samples page, just go to "Input->ContextMenu" from the navigation pane.

如果你想要簡潔的東西,這是一個簡化的例子:

If you want something concise, Here's a simplified example:

<ListBox ItemsSource="{StaticResource People}"
             Name="myListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}">
                    <controlsInputToolkit:ContextMenuService.ContextMenu>
                        <controlsInputToolkit:ContextMenu>
                            <controlsInputToolkit:MenuItem Header="Show in MessageBox"
                                                           Click="show_Click" />
                        </controlsInputToolkit:ContextMenu>
                    </controlsInputToolkit:ContextMenuService.ContextMenu>
                </TextBlock>
            </DataTemplate>
        </ListBox.ItemTemplate>
</ListBox>

與:

xmlns:controlsInputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"

代碼:

private void show_Click(object sender, RoutedEventArgs e)
    {
        var person = ((MenuItem)sender).DataContext as Person;
        if (null == person) return;
        MessageBox.Show("My Name is: " + person.Name);
        myListBox.SelectedItem = person;
    }

我希望這會有所幫助:)

I hope this helps :)

這篇關(guān)于右鍵單擊 Silverlight 4 應用程序中的列表框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應用程序 - 如何制作交互式菜單?)
How to add an icon to System.Windows.Forms.MenuItem?(如何向 System.Windows.Forms.MenuItem 添加圖標?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復的表單?)
Building a database driven menu with ASP.NET, JQuery and Suckerfish(使用 ASP.NET、JQuery 和 Suckerfish 構(gòu)建數(shù)據(jù)庫驅(qū)動的菜單)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應用程序并單擊菜單條)
主站蜘蛛池模板: 五月天国产在线 | 美女国产精品 | 欧美在线一区二区三区 | 久久99视频 | 久久精品无码一区二区三区 | 国产精品一区二区三区久久 | 中文字幕综合 | 中文视频在线 | 久久国产一区 | 欧美日韩a| 亚洲免费成人av | 国产一区二区精华 | 免费av在线| 黄色大片视频 | 欧美jizzhd精品欧美巨大免费 | 日韩久久综合网 | 国产成人免费一区二区60岁 | 色av一区二区三区 | 欧美日韩国产综合在线 | 黄a在线播放 | 中文字幕日韩欧美一区二区三区 | 欧美日韩不卡 | 欧美成人自拍 | 亚洲成人精品 | 欧美日韩激情 | 中文字幕一页二页 | 国产一伦一伦一伦 | 亚洲精品乱码久久久久久9色 | 欧美日韩视频 | 欧美视频一区二区三区 | 国产超碰人人爽人人做人人爱 | 黄色在线观看网址 | 新超碰97 | 久久久久久久97 | 久久久国产精品一区 | 精品国产乱码久久久久久影片 | 麻豆hd| 欧美日韩亚洲国产 | www.亚洲精品 | 国产在线视频三区 | 久久久91精品国产一区二区三区 |