Localizing attached properties in XAML/WinRT - windows

I'm attempting to localize my WinRT app. I don't need anything too fancy, so I've been using x:Uid on XAML elements in conjunction with resource files that have properties such as "PageTitleTextBox.Text" set. This method was working great until I ran into an issue with attached properties.
I've defined a few app bar buttons using similar markup to what I've seen in other examples:
<Button x:Name="AddFolderButton" Click="AddFolderButton_Tapped" x:Uid="FoldersPageAppBarAddFolderButton" AutomationProperties.Name="Test" Style="{StaticResource AppBarButtonStyle}">
<Button.Content></Button.Content>
</Button >
In this case, I'd like to localize AddFolderButton's label, currently defined by AutomationProperties.Name. I tried setting a key in my resource file to FoldersPageAppBarAddFolderButton.AutomationProperties.Name, but this fails on runtime.
Is it possible to localize this label using XAML, or do I need to do this programatically in the code-behind file?

You need to handle attached properties a bit differently, i.e. their namespace must be included in the reource key like this:
FoldersPageAppBarAddFolderButton.[using:Windows.UI.Xaml.Automation]AutomationProperties.Name
You can read more about it here.

Related

Image is not visible in android project with XAML forms - Xamarin even though provided solutions applied

I tried solutions from the following links but none worked.
where-to-put-images-for-xamarin-froms-application
developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images
image-not-showing-in-xamarin-forms-app.html
I used below syntax
<Image Source="lock.png" HeightRequest="20" WidthRequest="20" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="0" Grid.Column="0"></Image>
Here is the image for where i've kept image
No image displays
Edit
These are the only things in my XAML page.
In my case the issue was of assembly.
when trying all the possible solutions like
1.) Changing Build Action
2.) Adding Image to all the folders within Resources
3.) Naming Convention should not include - in File/Image Name.
4.) Changing Background Color
I also got one solution while searching for embedded Images that assembly was missing here.
This change worked for me in using Local Images.
Got that solution from this link
Right click the lock.png image and see if there is an option "include in project"
If there is, project cannot find image
In my case I need to use method Forms.Init(Context activity, Bundle bundle), in my SplashScreen OnCreate method and Activity class OnCreate method. But it also important that images build action properties is set on AndroidResource.

How to customize Xamarin.Forms app?

How can I customize the appearence of xamarin.forms components?
I want each button to have the same image, for instance. Or for all systems to share the same login screen with the same background image.
I know I can do that by adding one specific screen to each platform project. But I want to be able to customize the component itself. Example: All buttons will have the same background image no matter which platform is running.
I've read these:
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/styles/
http://code.tutsplus.com/tutorials/getting-started-with-xamarinforms-customizing-user-interface--cms-22144
The most promising one seems to be the last one. Is a custom renderer the only way to accomplish this? Can't I just add an image at the shared project and it automagicaly works for all platforms?
Thanks.
It's not absolutely clear, what exactly you want to reach... but I try to answer you.
If you use a shared project (based on template "Blank App (Xamarin.Forms shared)", you can use the same page / page-definition in all of your platforms.
You can add - e.g. a login-form in the shared-folder and then call it from code (e.g. from another page in the shared folder).
If you want to create your own controls, you can create "user-controls" and use it everywhere you want (what I recommend to every user).
You do this, by create a own class (e.g. with an Entry and a Label), implement the events and then instantiate it where you want to use it. E.G.
var OeFirma = new EntryErfassung(cDefaultText: "Firma", iMaximalLaenge: 45);
where OeFirma is the name of the object-instance on the page (to access it), EntryErfassung is my own class (that contains a description-label, an Entry an error-label and more) and cDefaultText is a parameter, that overtakes and set the default-text to the Entry and iMaximalaenge is a further parameter that is overtaken whereby my class then take care, that not more then 45 Characters are accepted for this Entry).
I have e.g. created a class with a description-label, a delete-button, an Entry and a error-label ad use it on all data-entry-forms.
If you want to change the look-and-feel of a specific control for a specific platform, you can create a "custom-render" (I have done this e.g. to change the font-size to the edit specific for iOS, as the font-sinze cannot be set in the XF-Entry control).
Hope this answers your question...
To do this, you can just specific a style in the App class, (you will need to change the app class to be made up of 2 partials: App.xaml & App.xaml.cs, and then create a ResourceDictionary to hold your customisations.
<Style TargetType="Button">
<Setter Property="Image" Value="MyImage.png"/>
</Style>
Hope that helps.
Cheers,
Tristan

Xamarin Forms - Access controls in Target application (iOS/Android)

I am using Xamarin.Forms, shared project template.
Here, I add controls to the content page such as a Label through say framework provided StackLayout.
Now in target apps - say for iOS/Andriod, I just need to set some text for this label. I have some platform specific code where I want to change the text value for the Label created in Shared Project.
How to do that?
I understand, Custom Renderers could be used. Is there any straight forward way that I am missing here?
You can, of course, use custom renderers... but imho it would be an overkill.
I'd use OnPlatform method - something like:
myLabel.Text = Device.OnPlatform<string>("text for iOS", "text for Android", "text for Windows Phone");
You can also do the same from XAML if you wish, like shown in this article (search "OnPlatform" there):
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/xaml-for-xamarin-forms/essential_xaml_syntax/
If the text you need is dynamic and you need to set it at run time from platform-specific project, than you need to assign your Label to some variable in the shared project and then reference this variable from platform projects.

Supported Cultures Box not available in manifest

This msdn link says that to add more language to your windows phone app, you need to make changes in the supported culture box in the properties page, but I can't find such box in the properties page as well as manifest page.
I tried searching all the tabs and I have uploaded the screenshots of properties page as well as manifest, but I'm not able to find the required box.
I have developed an application and updated on the store but only English (US) is the supported language and I'm not able to localize the app.
I'm not able to add screenshots as it requires more that 10 reputation.
Adding resource files
You do not specify what languages you support in the project properties any more. You only specify the default language in the app manifest.
You have to manually add one .resw file for each language you support. The files must all be named Resources.resw and must be placed in a sub-folder, named after the language, under a “Strings” folder in your project.
Accessing resources from xaml
You access the resources by setting the x:Uid property of a control to a unique name. Unfortunately the x:Uid property is not recognized by the properties window, neither in VisualStudio nor in Blend, so you must hand code it directly in the xaml file.
Example:
<TextBlock x:Uid="MyTextBlock" /> <Button x:Uid="MyButton" />
<TextBlock x:Uid="MyTextBlock" />
You must then add a resource with the uid-name with dot-notation, that is, after the dot you write the name of the property of the control in which you want the text.
Reference : http://www.jayway.com/2014/04/22/windows-phone-8-1-for-developers-localizing-apps/

I cant get LongLister Toolkit in my system

Hi I got following error
I added reference from phone.controls.assembly.toolkit but it doesnt work
The tag 'LongListSelector' does not exist in XML namespac 'clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit'.
When you add a new reference to your library, or in this case, your toolkit, you must also add a reference in your XAML code.
For eg:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
So in your XAML page, go right to the top, you will see a couple lines like the one above.
type xmlns:toolkit="LINK TO YOUR TOOLKIT"
When you type xmlns, intellisense will automatically prompt you to a list of available references. You can scroll down to find it.
Make sure you add a unique name like 'toolkit' or 'tool' after xmlns. So to access the LongListSelector, all you have to do is type
<toolkit:LongListSelector />

Resources