ContextMenu in Windows Phone project does not appear - windows-phone-8

I have problem with contextMenu in Windows Phone. It does not appear even in the project which I have downloaded from:
http://www.geekchamp.com/articles/wp7-contextmenu-in-depth--part1-key-concepts-and-api
When I click the button from the project above nothing happens.
I was searching for the solution but I have not found. Any ideas?
Code sample which doesn't work:
<Button Content="OpenContextMenu" Height="100" Width="270">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu VerticalOffset="50.0" IsZoomEnabled="True" x:Name="menu">
<toolkit:MenuItem Header="Add" Click="MenuItem_Click"/>
<toolkit:MenuItem Header="Update" Click="MenuItem_Click"/>
<toolkit:MenuItem Header="Delete" Click="MenuItem_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Button>

As MatDev8 has suggested, you need to "press and hold" for the context menu to appear.

Related

Change Theme in Avalon Dock

I am using Xceed.Wpf.AvalonDock in my WPF application.
I want a feature on the start page of my application which gives users an option to change the theme of the application by a click of a button/link.
Any suggestions how to do this?
Currently, I am using following code in XAML to set the Aero theme:
<avalonDock:DockingManager.Theme>
<avalonDock:AeroTheme/>
</avalonDock:DockingManager.Theme>
You can add a combo box which contains theme names, also each item's Tag is filled with its associated theme name:
<ComboBox>
<ComboBoxItem Content="Generic" />
<ComboBoxItem Content="Aero">
<ComboBoxItem.Tag>
<xcad:AeroTheme />
</ComboBoxItem.Tag>
</ComboBoxItem>
<ComboBoxItem Content="VS2010">
<ComboBoxItem.Tag>
<xcad:VS2010Theme />
</ComboBoxItem.Tag>
</ComboBoxItem>
<ComboBoxItem Content="Metro">
<ComboBoxItem.Tag>
<xcad:MetroTheme />
</ComboBoxItem.Tag>
</ComboBoxItem>
</ComboBox>
Then these tag names in items are used for binding to the Theme property in DockingManager:
<xcad:DockingManager Theme="{Binding ElementName=_themeCombo, Path=selectedItem.Tag}">
You can set the theme fix like this:
<xcad:DockingManager Grid.Row="1" MaxHeight="425"
AllowMixedOrientation="True"
BorderBrush="Black"
BorderThickness="1"
>
<xcad:DockingManager.Theme>
<xcad:MetroTheme />
</xcad:DockingManager.Theme>
</xcad:DockingManager>
You should be able to do this with a binding like any other property:
<avalonDock:DockingManager Theme="{Binding ThemeProperty}">
...
</avalonDock:DockingManager>
And then in your code just make your button or whatever control you use change ThemeProperty

Save selected text block on another page in Windows Phone 8

I have added following text blocks as part of MainPage.xaml:
<ScrollViewer>
<StackPanel>
<TextBlock x:Name="Test1" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Height="89" Width="220">
<Run>This is test text block1</Run>
</TextBlock>
<TextBlock x:Name="Test2" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Height="89" Width="220">
<Run>This is test text block2</Run>
</TextBlock>
<TextBlock x:Name="Test3" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Height="89" Width="220">
<Run>This is test text block3</Run>
</TextBlock>
</StackPanel>
</ScrollViewer>
I am trying to develop logic so that when I click the text block, the content of the text block can be saved as a link in on another page. The user should be able to click the link saved on the other page and jump to the relevant text block directly. In a way the saved text block will work as a bookmark to the associated text block. I would also like to extend the logic to remove the saved text block.
I am able to add/remove tapped textblock from textblock tbk1 to textblock tbk2 on the same page. This is the code I am using on Tap event:
private void listitemselected(object sender, System.Windows.Input.GestureEventArgs e)
{
{
foreach (var item in tbk1.SelectedItems)
{
tbk2.Items.Add(item);
}
}
}
However, how can I add the tapped text block on another page?
Can someone please point me to any reference material or guide me to understand the right approach to achieve this goal?
Thanks,
Aiseduk
you can use application storage to save your data
https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700361.aspx try this link it will solve your problem

How to reuse a flyout menu on WinRT

I have a project where I've lot a few diferent listview/gridviews itemstemplate.
yet all share the same flyout menu, something like this
<FlyoutBase.AttachedFlyout >
<MenuFlyout >
<MenuFlyoutItem x:Uid="lbl_action_sheet_title_add_to_playlist" Text="$add to playlist" />
<MenuFlyoutItem x:Uid="lbl_action_sheet_share" Text="$share" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
And I want to reuse it not copy paste it to N templates
Any ideas?
You could use an attached behavior to attach the menu from a DataTemplate resource.

How to keep a page open in the background when starting a new page in windows phone?

I have one simple application that have few pages.
On first page I have addMob, and that is working fine.
On that page I have a button for the contact page. When I open the contact page and return to the main page, addMob refreshes.
I do not want to do that. How can I put that first page in background without starting it again when user the returns from the contact page?
No. By design, in windows phone, you can have only one page active (visible) at a time. Ad controls will unload and refresh automatically when you navigate between pages. We have no control over this behaviour.
In my experience, I don't think we have to worry about Ads refreshing if navigation is fairly infrequent. As long as you expect the user to stay on a page for about 20 to 30 seconds on average, I would suggest not to worry about refresh. In fact, (again, in my personal experience) I receive more clicks with this implementation than having one static Ad control refreshing at a fixed interval.
But if you still have to avoid Ad refresh, here are couple of workarounds.
Option 1: Embed the "contact page" as a ContentControl/UserControl inside the Main page. Show and hide the contact control as required. Below is a very basic XAML design to demonstrate this.
<Grid>
<Grid.RowDefinition>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinition>
<AdControl Grid.Row="0" Height="80" />
<Grid Name="MainPage" Grid.Row="1">
<!-- Main page content -->
</Grid>
<view:ContactPage Name="Contacts" Grid.Row="1" Visibility="Collapsed">
<!-- Contact page content -->
</view:ContactPage>
</Grid>
Also, remember to handle BackButtonPress if you are going with this approach. The user would expect pressing back button, when the content page is visible, to take them back to Main page.
Option 2: If your application design would allow, use a Panaroma or Pivot control to show Main and Contact pages. Sample below,
<Grid>
<Grid.RowDefinition>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinition>
<AdControl Grid.Row="0" Height="80" />
<controls:Pivot Grid.Row="1">
<controls:PivotItem Header="Main page">
<!-- Main page content -->
</controls:PivotItem>
<controls:PivotItem Header="Contacts">
<!-- Contact page content -->
</controls:PivotItem>
</controls:Pivot>
</Grid>

How to open overlay menu from oncomplete of p:commandButton with Primefaces?

I'm using Primefaces 3.3.1 and have question.
I have p:commandButton inside p:column of p:dataTable. I can show overlay menu when button is clicked with xhtml shown below.
<p:commandButton id="btnID" icon="ui-icon-circle-triangle-s" style="height: 16px;">
<f:setPropertyActionListener value="#{searchItem}" target="#{bean.selectedSearchItem}" />
</p:commandButton>
<p:slideMenu overlay="true" trigger="btnID" my="left top" at="left bottom"
model="#{bean.menuModel}"/>
In this case, bean.menuModel can return menu data instantly. But I have another case also which pre-procsessing is required to make menu data ready. So I have this one too.
<p:commandButton ajax="true" id="historyButton" action="#{bean.getHistory()}"
icon="ui-icon-note" style="height: 16px;"
onstart="workingDialog.show();"
oncomplete="workingDialog.hide(); historyMenu.show();">
<f:setPropertyActionListener value="#{searchItem}" target="#{bean.selectedSearchItem}" />
</p:commandButton>
<p:menu overlay="true" widgetVar="historyMenu" my="left top" at="left bottom"
model="#{searchBean.menuModel}"/>
What I meant is, when button is clicked, it calls bean.getHistory() which starts loading menu data for that row, and show modal dialog with circling icon. When loading is finished, dialog will go away and overlay menu will be shown. What I can't do is a last part of this scenario. Above code fires exception.
java.lang.NullPointerException
javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:561)
org.primefaces.component.menu.BaseMenuRenderer.encodeOverlayConfig(BaseMenuRenderer.java:138)
org.primefaces.component.menu.MenuRenderer.encodeScript(MenuRenderer.java:45)
org.primefaces.component.menu.BaseMenuRenderer.encodeEnd(BaseMenuRenderer.java:39)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
Code shown below works fine, without menu related code.
<p:commandButton ajax="true" id="historyButton" action="#{searchBean.getHistory()}"
icon="ui-icon-note" style="height: 16px;"
onstart="workingDialog.show();"
oncomplete="workingDialog.hide();">
<f:setPropertyActionListener value="#{searchItem}" target="#{bean.selectedSearchItem}" />
</p:commandButton>
I guess this is easy question for experts. How can I open overlay menu from oncomplete?
Thanks in advance.
I could not find a solution for this issue but I came up with conclusion that what I wanted to do is not a good idea with the environment I'm working on.
First, I noticed that menu gets data from bean when row of data table is populated, not when menu is shown. And there is no lazy loading mechanism for menu. So button click -> get data for menu from server -> open menu cannot be done as I expected (at least it seems to me).
Second, I noticed putting menu in DataTable (under TabView in my case) causes very strange problem. When I update DataTable, some ajax related function stops working. I can't explain this problem to make you understand or believe, but app I'm working on is having this problem.
So, I gave up putting menu in DataTable in my app. Thank you for your attention.
I accept this answer not to lower my already LOW accept rate.