Programmatically localize a Text property in a WP8 app - windows-phone-8

As the title says, I'm trying to set (in the code) the Text property of a TextBlock to the right localized string in a Windows Phone 8 app.
I've tried this:
(VB)
statusValueTxt.Text = "{Binding Path=LocalizedResources.statusValueTxt_Charging,Source={StaticResource LocalizedStrings}}"
as I would use this code in the XAML, but it doesn't seem to work in the code.
Thanks in advance for any help.

There has to be a resource class (probably AppResources), that has multiple properties according to the localized strings you have in your app. Usage is then following:
yourTextBox.Text = AppResources.SomeResource;

Related

VisualStateManager with Windows Phone 8.1 BottomAppBar

I'm using VisualStateManager in a Windows 8.1 app to update the visibility of buttons on the BottomAppBar...
However this same XAML appears to not be supported for the BottomAppBar on Windows Phone 8.1.
When I attempt to update a button in Blend I get the error: An animation is trying to modify an object named '', but no such object can be found in the PageStandIn.
Is there a way to make this work or will I have to use code-behind to toggle the visibility manually?
is there any way to make this work so I can share the code from win81 to update the command bar?
The AppBars are very special, they are part of the System UI (in some sense) and thus somethings tend not work as expected.
Using storyboards don't work for updating them.
You can use the code behind, but if you are using an MVVM framework you should be able to Bind them to a Boolean and using a BooleanToVisibilityConverter to do the visibility management.
Model
public bool ShowAppButton {get; set;}
View
<AppBarButton x:Name="MyAppButton" Label="AppButton" Visibility="{Binding ShowAppButton, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
Hope this helps!

Change language of WinRT MapControl

I am using WinRT MapsControl in my universal application, which belongs to 'Windows.UI.Xaml.Controls.Maps'. I want to change language of maps when my application language is changed.
I see a Language property in there (Inherited from FrameworkElement), I tried setting it as
Language = "ar-SA"
in XAML and also through code, but it did not work. I tried searching about it in this documentation as well, but couldn't help myself.

Bind TreeView.SelectedItem to a property in the ViewModel in a WinRT app

In my Windows Store XAML app I’m using the TreeView control from the WinRTXamlToolkit and I’m attempting to two-way bind the SelectedItem property to a property on a ViewModel.
Out of the box, the SelectedItem property is read only and this makes sense because the control supports Virtualization.
I have seen some folk work around this with things like attached properties, helper methods and so forth, a great example of which is seen in this question
WPF MVVM TreeView SelectedItem
But all of the questions/solutions are not based on WinRT and all of my attempts to rework the solution code for a WinRT app have proven fruitless.
So, my question is, is this possible in a WinRT app? What am I missing?
Thanks
I'd skip trying to come up with a bindable property globally for the view model and instead use the IsSelectedBindingPath and IsExpandedBindingPath properties of the TreeView as in the debugging tools' example of the control's usage. Then when you want to select/expand an item from the view model - use a method similar to SelectItem() in my view model where I essentially set IsExpanded/IsSelected to true in item/node view models throughout the path from the root of the view model tree and load the content of the tree if the nodes in the expected path do not exist.

WinRT barcode scanner component

I have a Windows Store (Metro) application. I need to add support for scanning barcodes.
I tried using ZXing first. From what I was able to get working, you actually need to click and save an image for it to do the processing. There's no nice overlay of a red line "scanner" nor does it process a live feed. This isn't a very elegant solution. It works far better on Android. Basically, this won't work as I need a constant video and a constant search for a barcode to be in focus.
This blog (http://www.soulier.ch/?p=1275&lang=en) mentions that extrapolating a frame out of a WinRT video stream is not allowed in managed code which means I'd need to use C++.
So, are there any components out there that do this? Anything free or paid that I can get that would be written in C++ and can find and extrapolate a barcode? Learning C++ is not on my bucket list.
You can capture frames while displaying a preview with C# only. Here's an example control that does it:
https://winrtxamltoolkit.codeplex.com/SourceControl/latest#WinRTXamlToolkit/Controls/CameraCaptureControl/CameraCaptureControl.cs
Basically you need to create a MediaCapture object and associate it with a CaptureElement control to display the preview. Then you can use CapturePhotoToStreamAsync() to capture a frame to a stream of your selected encoding format and then have a go at it with your bar code reading code.
I made a lib for WinRT using ZXing & Imaging SDK.
It works well (but does not include any additional focus feature).
There is a lib and a sample app that you can try.
It works for barcodes and QRCode (barcode by default but just change the optional parameter in the scan function code to use QRCode)

How to Update IconicTile & LockScreen defined by WMAppManifest.xml

I'm trying to create an IconicTile for Windows Phone 8. I've defined with VS2012 the type of Tile Template to TemplateIconic and added a Tile Title and two images for small and medium.
If I pin my app to the start screen, I can choose between small and medium tiles like expected.
Now I want to update the IconicTile I defined in my WMAppManifest.xml. As I understand IconicTile, it needs to be updated in code and will also update the LockScreen icon and count, if I defined one. I've added a DeviceLockImageURI and this Extensions:
<Extensions>
<Extension ExtensionName="LockScreen_Notification_IconCount" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default"/>
<Extension ExtensionName="LockScreen_Notification_TextField" ConsumerID="{111DFF24-AA15-4A96-8006-2BFF8122084F}" TaskID="_default" />
</Extensions>
First question: Is this ConsumerID always the same or which ID is it?
To update the IconicTile I've defined in WMAppManifest.xml, I need to get hold of any pinned Tiles of my Application on the screen. I've read a lot of tutorials explaining how to add tiles manually from your application, but I only want to use the tile I've defined in WMAppManifest.xml. Therefore all tutorials recommended to get the current active Tile with this code:
ShellTile.ActiveTiles.FirstOrDefault();
ActiveTiles is an IEnumeration and only offers me: Equals, GetEnumerator, GetHashCode, GetType and ToString
Second question: What am I missing here? Does FirstOrDefault only work for FlipTiles or CycleTiles? I only want to use the IconicTile!
So I'm stuck at identifying the current active IconicTile on the screen, so that I can use an IconicTileData object to update the count or text of the IconicTile. What am I missing here?
For the first question:
I've seen a Tile ID when you create an IconicTile from Xml:
<wp:Tile Id="[Tile ID]" Template="IconicTile">
Maybe it is this ID? Otherwise I'll go with allways the same static ID, as there is no documentation on how to create this ID.
For the second question:
I've found the error: I was missing
using System.Linq;
This using enables access to the Linq Methods necessary to use FirstOrDefault or similar commands. I was mislead by
using System.Xml.Linq;
which is definitevly not the same Linq class ;)