GTK# - toolbar buttons with custom images - xamarin

When you create toolbar with buttons in GTK# in Xamarin Studio it seems that you can only assign images by StockId (Stock.New, Stock.Open etc).
Is there any way to assign custom images to toolbar buttons?

You can pass a Widget as a parameter in the ToolButton constructor:
var tbar = new Toolbar();
var icon = new Image("icon.png");
var button = new ToolButton(icon, "SO");
tbar.Add(button);
In this case, icon.png with no path assigned to it, should exist in the application directory, so set it to "Copy To Output Directory".
You can also create the Image by passing a Gdk image and mask, but that is another story...

Related

Multiple controls on Xamarin button?

I would like complex button, which has several text elements and which should change their state and color depending on button state.
Unfortunately, I see that Xamarin button has only predefined image and text parameters.
How to have multiple controls inside a button in Xamarin?
Visual state manager(Only XF 3.0+) have three states: normal, disabled, focused which is named "CommonStates", or you can create custom states.Maybe it could help:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual-state-manager
I think you must read more in content view, where you can add labels into stacklayout or grid with your own api bindable property, then use it wherever you want in your code:
https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.contentview

change back icon in toolbar inside Xamarin FormsPage

Using xamarin forms (PCL),
I searched a lot but Can not find the exact solution,
Can i change the back button in toolbar or at least should i be able to change its color and the title color as well?
I am not sure for changing back button, but I was changing back button and title color.
An example, in App.cs file OnStart method I set that LoginPage is first page with black title, on this way
MainPage = new NavigationPage(new LoginPage()) { BarTextColor = Color.Black };
Please try something like this, I have some other examples if this one doesn't work.

Setting template images when using an asset catalog in OS X

I have an asset catalog that holds all the images I'm using in toolbar buttons and I'd like to set them all to be template images. As far as I know there's no way to set the image of a button to be a template image in IB, but if I create an image as follows
NSImage *buttonImage = [NSImage imageNamed:#"imageName"];
[buttonImage setTemplate:YES];
then the image for 'imageName' becomes a template image throughout the app. Short of iterating every item in an asset catalog is there any way to do this?
I've tried setting the asset name in the catalog to *Template but that doesn't work. I've also tried renaming the backing images to include 'Template' but that also didn't work. Any suggestions?
You're supposed to be able to do this in the xcassets file. There's a setting in the Utilities Panel -> Attributes inspector. It's called "Render As" and contains an option for "Template Image". Unfortunately, there seems to be a bug that prevents this from actually working, or the setting is misleading.
However, you actually can do this in IB.
Select your NSButton or NSToolbarItem
Show the Utilities Panel
Switch to the Identity Inspector (CMD+SHIFT+3)
Go to the User Defined Runtime Attributes section.
Add a boolean attribute called image.template and leave it set to true
If you have an alternateImage set for your NSButton you'll probably want to do the same thing for that property. So, add another attribute to the list called alternateImage.template

Proper way of building application bar in WP7

I'am doing localized application in WP7 so I make my app bar in code. The problem appears when I have some form (registration, login etc.). In Blend everything looks all right, but when I emulate it on device my gird with textboxes, textblocks is totally different (sometimes they are on each other)
My solution is to build empty app bar in Blend (PhoneApplicationPage -> New (Common Properties)) and then make new one in code like that:
private void BuildApplicationBar()
{
// 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 OkAppBarButton = new ApplicationBarIconButton(new Uri("icons/ok.png", UriKind.Relative));
OkAppBarButton.Text = AppResource.OkAppBarButton;
ApplicationBar.Buttons.Add(OkAppBarButton);
OkAppBarButton.Click += new EventHandler(OkAppBarButton_Click);
ApplicationBarIconButton CancelAppBarButton = new ApplicationBarIconButton(new Uri("icons/cancel.png", UriKind.Relative));
CancelAppBarButton.Text = AppResource.CancelAppBarButton;
ApplicationBar.Buttons.Add(CancelAppBarButton);
CancelAppBarButton.Click += new EventHandler(CancelAppBarButton_Click);
}
Works good, but I wanted just to be sure is that the proper way to handle with that?
#dargod. There are a number of frameworks around to help build and bind the appbar. The key problem with the app bar that many people have complained about is that fact that the bar does not support commanding out of the box, so does not lend itself to MVVM.
Here are some links that may help
AppBarUtils
Bindable App bar

Storyboard change Target Control

I have created a Storyboard through Expression Blend. The Storyboard animates an Ellipse as a sortof placeholder for now. Now that I am back in Visual Studio, how can I make the Storyboard do the exact same thing but to a different control? I have a list of images:
private List<Image> items = new List<Image>();
Each object in items has been assigned with a name using the Name property:
items[i].Name = i.ToString();
'i' in this case is the counter.
How do I therefore make the Storyboard target "one" specific object within the list for the moment. Later, I shall try to make the Storyboard do the same for all of them.
Any help is highly appreciated.
I fixed the problem by having a Storyboard Completed event and changing the target using:
Storyboard.SetTargetName();

Resources