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

右鍵單擊 Silverlight 4 應(yīng)用程序中的列表框

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

問題描述

我正在嘗試實(shí)現(xiàn)我過去在 Winforms 應(yīng)用程序中認(rèn)為理所當(dāng)然的內(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 應(yīng)用中有一個列表框.我想執(zhí)行以下操作:

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

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

從我目前的研究來看,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,我需要對列表框進(jìn)行某種命中測試.我不知道該怎么做,我的 google-fu 也沒有幫助.
  2. 一旦我確定了鼠標(biāo)下的索引,我該如何實(shí)際選擇項(xiàng)目?
  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 的部分中,設(shè)置 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 屬性設(shè)置為相應(yīng)的點(diǎn)擊事件處理程序

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

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

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

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

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

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

Add any custom logic to the event handler

示例頁面中有一個示例,只需從導(dǎo)航窗格中轉(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 應(yīng)用程序中的列表框的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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# 控制臺應(yīng)用程序 - 如何制作交互式菜單?)
How to add an icon to System.Windows.Forms.MenuItem?(如何向 System.Windows.Forms.MenuItem 添加圖標(biāo)?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
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自動化控制桌面應(yīng)用程序并單擊菜單條)
主站蜘蛛池模板: 老女人毛片 | 久久久久久久网 | 欧美视频在线一区 | 日本在线播放 | 亚洲精品日韩精品 | 久久99热这里只频精品6学生 | 久久国产精品99久久人人澡 | 欧美一区二区三区在线视频 | 一区二区三区中文字幕 | 亚洲 欧美 日韩 在线 | 亚洲免费专区 | 日韩性生活视频 | 久久爱综合 | 国产性生活视频 | 成人黄色小视频 | 国产超碰在线 | 国产日韩久久 | 私库av在线 | 成人免费视频一区二区 | 日韩av在线免费看 | 国产精品一级二级 | 亚洲香蕉在线 | 中文字幕在线观看日韩 | 久久99久久久| 国产免费小视频 | 欧美日韩亚洲综合 | 国产精品久久久久久久久久久久久 | 欧美激情久久久 | 日本少妇高潮达到高潮 | 成人做爰www看视频软件 | 中文字幕第7页 | 日韩综合在线观看 | 国产一级二级三级 | 欧美国产日韩在线 | 拍床戏真做h文黄肉1v1 | 国产精品综合 | 天天爽夜夜爽夜夜爽 | 91丨porny丨成人蝌蚪 | 久久精品久久久久 | 欧美精品第一页 | 国产小视频在线观看 |