Relative or absolute path mess - windows-phone-7

I'm developing a Windows Phone 7.1 application.
I have the following folders structure:
- Images (**folder**)
|
- appbar.questionmark.rest.png
- Views(**folder**)
|
- About.xaml
- MainPage.xaml
...
I'm trying to create an app bar programmatically with:
private void SetUpAppBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("..//Images//appbar.questionmark.rest.png", UriKind.Relative));
helpButton.Text = AppResources.Help;
helpButton.Click += new EventHandler(helpButton_Click);
ApplicationBar.Buttons.Add(helpButton);
// Create a new menu item with the localized string from AppResources.
ApplicationBarMenuItem appBarHelpMenuItem = new ApplicationBarMenuItem(AppResources.Help);
appBarHelpMenuItem.Click += new EventHandler(helpButton_Click);
ApplicationBar.MenuItems.Add(appBarHelpMenuItem);
}
But I can't see the icon on app bar. What am I doing wrong?
I have test with this:
ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("..//Images//appbar.questionmark.rest.png", UriKind.Relative))
But I get an invalid path exception. I've also changed UriKind to Relative, Absolute and with AbsoluteOrRelative.
appbar.questionmark.rest.png is marked as Resource, and copy to directory is set to "don't copy".

The pictures Build Action should be Content.
ApplicationBarIconButton helpButton = new ApplicationBarIconButton(new Uri("/Images/appbar.questionmark.rest.png", UriKind.Relative));
Try this i hope this will work.:)
This is how MSDN describes how to add a button to the AppBar
ApplicationBarIconButton button1 = new ApplicationBarIconButton();
button1.IconUri = new Uri("/Images/YourImage.png", UriKind.Relative);
button1.Text = "button 1";
ApplicationBar.Buttons.Add(button1);
I think your problem is that your picture is set as a Resource and not as Content.

Related

How to add icon to Action Sheet Popup on Xamarin forms?

I'm using Action Sheet Popup of the library Rg.Plugins.Popup on Xamarin Forms.
I want to display the image as below:
How to add an icon to Action Sheet Popup on Xamarin forms?
This is my code:
public Task<string> ShowActionSheetDialogAsync(string title, string cancelString = null, string destructive = null, CancellationToken? token = null, string[] arrayButtons = null)
{
return UserDialogs.Instance.ActionSheetAsync(title, cancelString,destructive, cancelToken: token,buttons:arrayButtons);
}
Or you can suggest another idea which might also show.
Please help me!
Use aritchie/userdialogs instead, it provides icon option for the item in list , check API .
Usage
IUserDialogs d = UserDialogs.Instance;
ActionSheetConfig config = new ActionSheetConfig();
List<ActionSheetOption> Options = new List<ActionSheetOption>();
Options.Add(new ActionSheetOption("1" , null , "info.png"));
Options.Add(new ActionSheetOption("2", null, "info.png"));
ActionSheetOption cancel = new ActionSheetOption("Cancel",null,null);
config.Options = Options;
config.Cancel = cancel;
d.ActionSheet(config);
Screen shot
This is platform-specific, so wrap it in DependencyService for example.
This is how you add image to an ActionSheet action:
UIImage img; //the image
var action = new UIAlertAction();
action.SetValueForKey("image", img);
Then add this UIAlertAction to a UIActionSheet. (You should also set Title and Action, of course)

Xamarin UWP brand toolbar

I'm using Visual Studio 2015 and made a Xamarin project to support iOS, Android and UWP.
I want rebrand the toolbar, and on iOS and Android its possible to set a background color and a picture in the toolbar.
But for Universal Windows Platform this seems impossible.
So I want to set my own TopAppBar with a picture, and hide the current toolbar for UWP;
In my MainPage.xaml.cs I've;
#if __ANDROID__ || __IOS__
ToolbarItems.Add(new ToolbarItem("+", "", () => App.Navigation.PushAsync(new AddAccount())));
#endif
So for UWP there would be no items on the toolbar. But it still appears.
I cannot find any documentation on how to;
-customize the toolbar for UWP
-hide the toolbar for UWP
I've tried to add a toolbar like so;
var _globalAppBar = new AppBar();
_globalAppBar.Height = 128;
_globalAppBar.Background = new SolidColorBrush(Colors.Green);
BitmapImage bmI = new BitmapImage();
bmI = new BitmapImage(new Uri("ms-appx:///Assets/logo.png", UriKind.RelativeOrAbsolute));
var imageBrush = new ImageBrush();
imageBrush.ImageSource = bmI;
_globalAppBar.Background = imageBrush;
AppBarButton abbtn = new AppBarButton();
abbtn.Label = "Add";
_globalAppBar.Content = abbtn;
this.BottomAppBar = _globalAppBar;
But that results in having two toolbars at the top...
So it's better to modify the existing toolbar created by Xamarin, but I don't know how to access it from the 'public MainPage()' of the UWP project.
I just tried to redo your problem. I can hide the toolbar when I clear the toolbaritems.
Also I have to call
NavigationPage.SetHasNavigationBar(this, false);
on the page.

Windows Phone 8 global application bar localization

I am trying to create a localized windows phone 8 app , and I am creating a global application bar . However I am unable to set the text of the items inside the bar using the resource , anyone have an idea how to do that ? I am also unable to get it in code .
you can reuse the commented code in the template's MainPage.xaml.cs:
private void BuildLocalizedApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
//Search in AppResources.Search is a key of a string in the resource files (.resx)
appBarButton.Text = AppResources.Search;
ApplicationBar.Buttons.Add(appBarButton);
// Create a new menu item with the localized string from AppResources.
//Search in AppResources.Search is a key of a string in the resource files (.resx)
ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.Search);
ApplicationBar.MenuItems.Add(appBarMenuItem);
}
unfortunately the app bar is not a traditional Silverlight control so you have to create programmatically in every page if you want it localized.

How to make a custom SettingsPane look like the permissions in the Settings Charm Windows 8

I have created a custom Settings Charm options for "About" in my win8 app. I would like the style to look like the Permissions pane. Is the best way to just hardcode these values or is there a way to make it set to the default.
Current Look:
Desired Look:
This is where I got my example code:
http://code.msdn.microsoft.com/windowsapps/App-settings-sample-1f762f49
In App.xaml.cs, create color variables
private SolidColorBrush _background = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x3E, 0x00));
// FF003E00
private SolidColorBrush _Hbackground = new SolidColorBrush(Color.FromArgb(0xEE, 0x00, 0x8A, 0X00));
Now, when you are creating the settings menu for permissions,
private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
var Permissions= new SettingsCommand("Permissions", "Permissions", (handler) =>
{
var settings = new SettingsFlyout();
settings.Content = new AboutUserControl();
//settings.HeaderBrush = new SolidColorBrush(_background);
//settings.Background = new SolidColorBrush(_background);
settings.HeaderBrush = _Hbackground;
settings.Background = _background;
settings.HeaderText = "Permissions";
settings.IsOpen = true;
});
args.Request.ApplicationCommands.Add(Permissions);
UICommandInvokedHandler handler1 = new UICommandInvokedHandler(onSettingsCommand);
// throw new NotImplementedException();
}
So as you can see you can set the header background color as well as the body background color. With this code, you can set the color of your choice for the settings menu
if you are taking about the Background color, than you can define a global Background color in StandardStyles.xaml or App.xaml to use it everywhere. You don't have access to System theme color information so you do have to hardcode it.

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

Resources