在LongListSelector ItemTemplate - Windows Phone中引用数据绑定ContextMenu

时间:2012-07-27 05:26:09

标签: silverlight windows-phone-7 contextmenu silverlight-toolkit longlistselector

我正在为Windows Phone 7.5应用程序编写Silverlight。

我想在LongListSelector中引用ContextMenu,因为我想在调用ContextMenu .IsOpen事件后立即将false设置为Click。我的想法是,这应该自动发生,但事实并非如此。

我的一个MenuItem设置<Grid>collapsedvisible的可见度,模仿PopUp。虽然代码执行正常,但可见性确实发生了变化。除非ContextMenu关闭,否则应用程序的UI不会显示网格。

我的LongListSelector的XAML,其中包含我希望在ContextMenuItem Click事件中引用的名为ContextMenu的{​​{1}}。

Menu

我在ContextMenuItem Click事件背后的代码

 <toolkit:LongListSelector x:Name="moviesLongList" Background="Transparent" IsFlatList="False" GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}" GroupItemTemplate="{StaticResource GroupItemTemplate}" SelectionChanged="moviesLongList_SelectionChanged" GroupViewClosing="moviesLongList_GroupViewClosing" GroupViewOpened="moviesLongList_GroupViewOpened">

                    <toolkit:LongListSelector.GroupItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel/>
                        </ItemsPanelTemplate>
                    </toolkit:LongListSelector.GroupItemsPanel>

                    <toolkit:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Height="91" Margin="20,0,0,20" Orientation="Horizontal">
                                <toolkit:ContextMenuService.ContextMenu >
                                    <toolkit:ContextMenu x:Name="Menu" Opened="ContextMenu_Opened" Loaded="Menu_Loaded" Unloaded="Menu_Unloaded">
                                        <toolkit:ContextMenu.ItemTemplate>
                                            <DataTemplate>
                                                 <toolkit:MenuItem Header="{Binding}" Click="ContextMenuButton_Click" LostFocus="MenuItem_LostFocus" />
                                            </DataTemplate>
                                        </toolkit:ContextMenu.ItemTemplate>
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>

                                <Border HorizontalAlignment="Left" Width="61" Height="91" Background="{Binding ID, Converter={StaticResource ThumbImageConvert}}" />
                                <StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="395">
                                    <TextBlock x:Name="titleTextBox" Text="{Binding Title, Converter={StaticResource TitleConvert}}" Margin="6,0,6,0" d:LayoutOverrides="Width" FontSize="{StaticResource PhoneFontSizeLarge}" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                                    <TextBlock x:Name="yearTextBox" Text="{Binding Year}" Margin="12,0,0,0" HorizontalAlignment="Left" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="{StaticResource PhoneSubtleBrush}" />
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </toolkit:LongListSelector.ItemTemplate>

                </toolkit:LongListSelector>

我在 private void ContextMenuButton_Click(object sender, RoutedEventArgs e) { // // This is where I want to set Menu.IsOpen = false to close the ContextMenu. // if ((sender as MenuItem).Header.ToString() == "lend movie") { DisableAppBarIcons(); LendPopUpOverlay.Visibility = System.Windows.Visibility.Visible; } if ((sender as MenuItem).Header.ToString() == "return to collection") { ... Do stuff } if ((sender as MenuItem).Header.ToString() == "add to boxset") { ... Do stuff } if ((sender as MenuItem).Header.ToString() == "delete") { ... Do stuff } } 事件中设置了ContextMenu的ItemSource。这些字段都是ContextMenu_Opened类型。

List<String>

0 个答案:

没有答案