SystemTray for Pivot Item content - c#

I have a Pivot Control in MainPage.xaml page. I add in the PageOne.xaml.cs as pivot item using
private void OnLoadingPivotItem(object sender, PivotItemEventArgs e)
{
if (e.Item.Content != null)
{
// Content loaded already
return;
}
Pivot pivot = (Pivot)sender;
if (e.Item == pivot.Items[0])
{
e.Item.Content = new PageOne();
}
}
Thing is not working so fine, but I have tried to fix them, for example,
// NavigationService.Navigation(new Uri());
// need to change to
(App.Current as App).RootFrame.Navigate( new Uri());
// ApplicationBar for PivotItem
appBar = ((PhoneApplicationPage)((PhoneApplicationFrame)Application.Current.RootVisual).Content).ApplicationBar;
Now, I need to show ProgressIndicator on my PivotControl MainPage.xaml from my PageOne.xaml.cs code.
_progressIndicator = new ProgressIndicator
{
IsIndeterminate = true,
IsVisible = false,
};
SystemTray.SetProgressIndicator(this, _progressIndicator);
But progressIndicator doesn't show, what should I do? My guess is to call the SystemTray of RootFrame but I am not sure how to.

Try change the property IsVisible to true.
Wish this can help you.

I need to pass MainPage as reference to PageOne, and put it as parameter when using SystemTray.SetProgressIndicator.
In MainPage.xaml.cs
e.Item.Content = new PageOne(this);
Here is the constructor code from PageOne.xaml.cs
public PageOne(MainPage page) {
_progressIndicator = new ProgressIndicator
{
IsIndeterminate = true,
IsVisible = false,
};
SystemTray.SetProgressIndicator(page, _progressIndicator);
}

Related

Set Back Button Title on Xamarin Forms C#

im quite new to c# and Xamarin and I've just encountered a problem. I can't seem to be able to set the back button title on a navigation page. Ive tried using the static SetBackButtonTitle method but it does not seem to set the back button to the title I want which is
'Test' but instead its giving me the 'default' title which is "Back".
// The root page of your application
var content = new ContentPage();
var CompanyName = new Label();
CompanyName.HorizontalTextAlignment = TextAlignment.Center;
CompanyName.Text = "Test";
var NextPage = new Button();
NextPage.Text = "Next Page";
NextPage.Font = Font.SystemFontOfSize(NamedSize.Large);
NextPage.BorderWidth = 1;
NextPage.HorizontalOptions = LayoutOptions.Center;
NextPage.VerticalOptions = LayoutOptions.CenterAndExpand;
var layout = new StackLayout();
layout.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.Children.Add(CompanyName);
layout.Children.Add(NextPage);
content.Content = layout;
var content2 = new ContentPage();
var navigation = new NavigationPage(content);
NavigationPage.SetHasBackButton(navigation,true);
NavigationPage.SetBackButtonTitle(navigation,"Test");
NextPage.Clicked += NextPageClicked;
async void NextPageClicked(object sender, EventArgs e)
{
await navigation.PushAsync(content2);
}
MainPage = navigation;
}
If you want to change the back button's title(at the left in the navigation bar) in the second page, you should call the method SetBackButtonTitle with first page as parameter. So please modify NavigationPage.SetBackButtonTitle(navigation,"Test"); to NavigationPage.SetBackButtonTitle(content,"Test");
For those who use Xamarin.Forms WPF if you want to change back button title you can do this:
protected override void OnDisappearing()
{
base.OnDisappearing();
Title = "";
}
protected override void OnAppearing()
{
base.OnAppearing();
Title = "MyTitle";
}

Tell ActivityIndicator to show yourself and then navigate to another page

On Xamarin.Forms Project, I am trying to tellActivityIndicator to show yourself and then navigate to another page
activityIndicatorObject = new ActivityIndicator()
{
HorizontalOptions = LayoutOptions.CenterAndExpand,
Color = Color.Red,
IsVisible = false,
IsRunning = false,
IsEnabled = false,
BindingContext = this,
};
ViewBookButton = new Button{ Text = "view book" };
ViewBookButton.Clicked += ViewBook;
protected void ViewBook(Object sender,EventArgs e)
{
//Go To View Book Page
activityIndicatorObject .IsVisible = true;
activityIndicatorObject .IsRunning = true;
activityIndicatorObject .IsEnabled = true;
activityIndicatorObject .SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");
this.IsBusy = true;
Navigation.PushAsync(new BookPage());
this.IsBusy = false;
}
ActivityIndicator doesn't showing? How I can make it showing?
As I understand you tell ActivityIndicator show yourself and then navigate to another page. And new page hasn't own ActivityIndicator. I would like to suggest you make your hard operations in OnAppearing method of BookPage.
protected override void OnAppearing()
{
base.OnAppearing();
activityIndicator.IsVisible = true;
// Some hard operations
activityIndicator.IsVisible = false;
}
Or use binding instead of activityIndicator.IsVisible = true;

How to show toast after performing some functionality in windows phone 8

I want to show something like toast after some functionality performed. i-e I have a save button and I want that when it pressed then a toast should be shown with the text Record Saved etc. I read posts that show toasts are only for back-ground agents. I know someone will give me good guidance. please specify some code.
Thanks
You can use the Toast Prompt from the Coding4Fun Toolkit to perform a toast notification via code. After referencing the toolkit (ideally via NuGet) you can use it like this:
ToastPrompt toast = new ToastPrompt();
toast.Title = "Your app title";
toast.Message = "Record saved.";
toast.TextOrientation = Orientation.Horizontal;
toast.MillisecondsUntilHidden = 2000;
toast.ImageSource = new BitmapImage(new Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute));
toast.Show();
I prefer ProgressIndicator in my apps but you can use Popup or ToastPrompt.
Sample project.
// popup member
private Popup popup;
// creates popup
private Popup CreatePopup()
{
// text
TextBlock tb = new TextBlock();
tb.Foreground = (Brush)this.Resources["PhoneForegroundBrush"];
tb.FontSize = (double)this.Resources["PhoneFontSizeMedium"];
tb.Margin = new Thickness(24, 32, 24, 12);
tb.Text = "Custom toast message";
// grid wrapper
Grid grid = new Grid();
grid.Background = (Brush)this.Resources["PhoneAccentBrush"];
grid.Children.Add(tb);
grid.Width = this.ActualWidth;
// popup
Popup popup = new Popup();
popup.Child = grid;
return popup;
}
// hides popup
private void HidePopup()
{
SystemTray.BackgroundColor = (Color)this.Resources["PhoneBackgroundColor"];
this.popup.IsOpen = false;
}
// shows popup
private void ShowPopup()
{
SystemTray.BackgroundColor = (Color)this.Resources["PhoneAccentColor"];
if (this.popup == null)
{
this.popup = this.CreatePopup();
}
this.popup.IsOpen = true;
}
// shows and hides popup with a delay
private async void ButtonClick(object sender, RoutedEventArgs e)
{
this.ShowPopup();
await Task.Delay(2000);
this.HidePopup();
}
using Windows.UI.Notifications;
var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var txtNodes = toastXmlContent.GetElementsByTagName("text");
txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("First Line"));
txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Second Line" ));
var toast = new ToastNotification(toastXmlContent);
var toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toast);

Slow app changing page in WP8

I have an app with a ListBox; when the user taps an item i launch a new page that invoke a MVVM method and the fills its ListBox. When the user taps the first ListBox it does not change page immediately, waits 2-3 seconds and then shows the new page and it is not responsive. How can i activate the new page, showing the ProgressIndicator and fill the new list?
Here is the code for the second list:
protected override async void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
int id;
if (NavigationContext.QueryString.ContainsKey("id"))
{
id = Convert.ToInt16(NavigationContext.QueryString["id"]);
SystemTray.SetIsVisible(this, true);
SystemTray.SetOpacity(this, 0.5);
progressIndicator = new ProgressIndicator();
progressIndicator.IsVisible = true;
progressIndicator.IsIndeterminate = true;
SystemTray.SetProgressIndicator(this, progressIndicator);
var x=await App.viewModel.MyDBMethod(id);
this.DataContext = App.viewModel;
this.mPivot.SelectedIndex = 0;
progressIndicator.IsVisible = false;
progressIndicator.IsIndeterminate = false;
}
}
}

Tooltip in Datagrid, added from code-behind

I'm new to wpf and im having trouble adding tooltips to my datagrid header from code-behind.
I need to use autogeneratecolumns on the datagrid which rules out xaml editing. All examples i could find involved som xaml editing.
I've tried to add it the DataGridTextColumn without succeding
private void dataGrid1_AutoGeneratedColumns(object sender, EventArgs e)
{
foreach (DataGridTextColumn item in dataGrid1.Columns)
{
ToolTip tooltip = new ToolTip();
tooltip.Content = "Test";
ToolTipService.SetToolTip(item, tooltip);
}
}
I can see that the ToolTip variable is set in the WPF visualizer but nothing shows in the datagrid.
Help!
I ended up using this approach:
private void dataGrid1_AutoGeneratingColumn(object sender,DataGridAutoGeneratingColumnEventArgs e)
{
Style style = new Style(typeof(DataGridColumnHeader));
Trigger trigger = new Trigger();
trigger.Property = IsMouseOverProperty;
trigger.Value = true;
Setter setter = new Setter();
setter.Property = ToolTipProperty;
setter.Value = "Your tooltip";
trigger.Setters.Add(setter);
style.Triggers.Add(trigger);
e.Column.HeaderStyle = style;
}

Categories