fire a popup when ApplicationBarMenuItem clicked - windows-phone-7

I need to fire a popup when ApplicationBarMenuItem clicked. but nothing happen when I click MenuItem. here is my code;
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Go by date" Click="GoByDate_Click" />
</shell:ApplicationBar.MenuItems>
private void GoByDate_Click(object sender, EventArgs e)
{
Popup popup = new Popup();
popup.Height = 480;
popup.Width = 480;
popup.VerticalOffset = 100;
DatePopupControl datePopup = new DatePopupControl(); // just a user control comes when add new
popup.Child = datePopup;
popup.IsOpen = true;
}

Something is wrong with your DatePopupControl, because your code worked fine for my own test control. Can you provide DatePopupControl source code?
Alright, let me try to guess. My first theory is: there is nothing to show in this popup.
For example, if you add a userControl, which has only Grid tag inside without anything, you will see in the editor in Visual Studio, but it won't be visible as a popup child. But if you add a single textblock, it will be.

Related

xamarin android (not forms) button tag

I need to pass some additional information with a button press. From what I could gather reading on the web I should use a button tag.
So far I have this
Button button = new Button(this);
button.Text = "Test Button";
button.SetBackgroundColor(Android.Graphics.Color.Black);
button.SetTextColor(Android.Graphics.Color.White);
button.Tag = "hello";
button.Click += ClickEvent;
And this is the handler:
public void ClickEvent(object sender, EventArgs e)
{
Android.Widget.Button button = (Android.Widget.Button)sender;
var test = button.Tag;
}
This works, but I need to be able to pass 3 ints of data. I have tried using an array but I have no idea how to read it in the handler as it comes back as a java.object.
Can anyone please push me in the right direction?

list picker in popup windows phone

I am using a list picker in popup. But when I click on list picker, its full mode opens behind popup. How can I make my list picker full mode window to appear above popup.
MY list picker is in the user control called WindowsPhoneControl1
Popup Mypopup = new Popup();
Mypopup.Height = 300;
Mypopup.Width = 400;
Mypopup.VerticalOffset = 100;
WindowsPhoneControl1 Mycontrol = new WindowsPhoneControl1();
Mypopup.Child = Mycontrol;
Mypopup.IsOpen = true;
i didn't find a solution
thank you
Try defining the Popup in XAML.
such as so:
<Popup IsOpen="true" Name="MyPopup" Height="300" Width="400" VerticleOffset="100"/>
Make sure IsOpen is true, then try to right-click on the ListPicker and choose it's order: bring-to-front.
I know it's simple, but I didn't see you mention trying it, so give it a shot!

how to add/show a UserControl (e.g. popup) in a WP7 app page?

hi i have created a user control.
now i want to add this control to a page e.g. when the user clicks a button (important is, that i dont want to add it direcly in xaml, i want to add id in the c# code section)
how to so this?
In your button's Click event, you could do something like:
MyControl control = new MyControl();
// Set whatever properties you need in your control here
LayoutRoot.Children.Add(control);
if (listBox1.Items.Count == 0)
{
Popup popup = new Popup();
WPCpopup po = new WPCpopup(popup);
popup.Width = System.Windows.Application.Current.Host.Content.ActualWidth;
popup.Child = po;
popup.VerticalOffset = 300;
popup.IsOpen = true;
}
WPCpopup is usercontrol

ApplicationBarIconButton is null

Why is my ApplicationBarIconButton null?
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" x:Name="appBar">
<shell:ApplicationBarIconButton x:Name="appbarSave"
IconUri="/Icons/appbar.save.rest.png Text="Save" IsEnabled="False"
Click="appbarSave_Click" />
</shell:Application Bar>
</phone:PhoneApplicationPage.ApplicationBar>
The appBarSave object is null, and trying this:
Initialize Component();
appbarSave.IsEnabled = true;
Results in a NullReferenceException. The only place the object works is in the click event (if I enable it):
private void appbarSave_Click(object sender, EventArgs e)
{
ApplicationBarIconButton button = (ApplicationBarIconButton)sender;
button.IsEnabled = false;
}
I would really like to be able to start the save button as disabled and enabled it later.
I remember running into this issue before: there's an explanation here. An easy workaround is just to instantiate it in code-behind rather than xaml (like here).
private ApplicationBarIconButton SaveEdit;
private void InitAppBar()
{
ApplicationBar appBar = new ApplicationBar();
SaveEdit = new ApplicationBarIconButton(new Uri("images/appbar.check.rest.png", UriKind.Relative));
SaveEdit.Click += new EventHandler(OnClick_Check);
SaveEdit.Text = Strings.Save_button;
appBar.Buttons.Add(SaveEdit);
ApplicationBarIconButton CancelEdit = new ApplicationBarIconButton(new Uri("images/appbar.close.rest.png", UriKind.Relative));
CancelEdit.Click += new EventHandler(OnClick_Cancel);
CancelEdit.Text = Strings.Cancel_button;
appBar.Buttons.Add(CancelEdit);
ApplicationBar = appBar;
}
try this
Microsoft.Phone.Shell.ApplicationBarIconButton btn = ApplicationBar.Buttons[0] as Microsoft.Phone.Shell.ApplicationBarIconButton;
btn.IsEnabled = false;
I use a bindable app bar control from here The download link is at the bottom of the article.
Makes life much easier and saves you from having to put code in the code behind.
I made this mistake today, the x:Name is ignored.
The ApplicationBar is part of the page already, whether you create it in XAML or not. There is no need to create a new one. Just use the ApplicationBar property in the code behind file.
Initialize Component();
ApplicationBar.IsEnabled = true;
I do it so, example for change icon
ApplicationBarIconButton btn = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
btn.IconUri = new Uri("/images/play.png", UriKind.Relative);

OnClick on generated Textblock

Howdy,
I'm generating a bunch of Textblocks in a StackPanel. I would love to open another page when clicking on one Textbox:
sp.Children.Add(new TextBlock { Text = "Click me, I wanna open new content" });
How could I do that, it's probably something with "triggers" but I couldn't find anything on the web :-/.
Thanks!
You could use the Toolkit to add a gesture listener for the Tap event.
Alternatively you could use a HyperlinkButton as this contains a Click event.
Edit:
Example of using HyperlinkButton:
var sp = new StackPanel();
var hlb = new HyperlinkButton {Content = "click me"};
hlb.Click += hlb_Click;
sp.Children.Add(hlb);
ContentPanel.Children.Add(sp);
private void hlb_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/AnotherPage.xaml", UriKind.Relative));
}
Use TextBlock.ManipulationStarted event to detect a touch on it.

Resources