久久久久久久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自動化控制桌面應用程序并單擊菜單條)
主站蜘蛛池模板: 成人亚洲片| 伊人免费在线观看 | 国产精品视频网站 | 午夜网 | 国产在线播放av | 久草在线免费资源 | 日韩电影中文字幕 | 国产性网 | 国产精品视频久久 | 成人国内精品久久久久一区 | 精品av| 成人在线免费 | 久久精品中文字幕 | 国产95在线 | 欧洲一区二区三区 | 91正在播放| 日本中文字幕日韩精品免费 | 国产美女永久免费无遮挡 | 亚洲人成人网 | 久久国产三级 | 精品综合 | av中文字幕在线观看 | www.色五月.com | 国产精品久久久久久久久免费相片 | 成人a网 | 韩国久久精品 | 欧美日韩一区二区三区四区 | 成人精品一区 | 国产精品成av人在线视午夜片 | 国产成人精品网站 | wwww.8888久久爱站网 | 蜜桃官网 | 亚洲成人精品 | 国产精品免费一区二区三区四区 | 日韩在线观看网站 | 欧美精品久久久 | 成人午夜精品 | 久久久久国产精品一区三寸 | 欧美日韩在线一区二区三区 | 亚洲午夜一区二区 | 综合色久|