XAML usage question - wpf

As far as I know, XAML is only used in WPF and Silverlight, isn't it?
Thanks.

No, it is also used in Windows Workflow Foundation:
Using Workflow Markup

XAML is also the basis for XPS.

It is also used in Office 2007+ *x formats

You can use it for whatever you like (beginning with .NET 4.0 if I'm not mistaken, didn't try it in 3.5).
However, if you do so, please also use the other good things .NET has to offer, such as "INotifyPropertyChanged" and dependency properties. Otherwise whatever you create will be a less - than - optimal solution.

There is a huge mistake I often see people make when they say, "XAML is UI markup." It's not. You can have XAML with no UI whatsoever. XAML is, in essence, an XML object graph. It is markup for creating classes. It provides the parser with instructions on how to generate instances of types and set properties on those types. This is extremely useful for creating UI in WPF and Silverlight but can also extend to sample data, view models, and other constructs. As mentioned here, it is also used in Workflow and other areas.

Related

dymamic text binding in a WPF TextBlock

Sorry for the noob question.... but
I have a rather large unilingual application that I have to make multilingual, meaning no resource file. I don't have the option of using the culture information but need to do it more on the fly at runtime so that the user can change languages either on startup or menu pick while in the application. I can handle that part ok. I realise there are traditional ways to set these values but I'm hoping to find a better solution.
What I'd like to be able to do is the following
First of all is this even possible? I've taken a pretty good look around and didn't really find anything close to what I'd like to do. I would even be willing create a few user controls if that was the solution. In the end I'll have to do this for buttons, labels, datagrid headers and messages(these are easy lol)
Any thoughts would be appreciated.
Thanks
Yes it is possible. Try this article: Creating an Internationalized Wizard in WPF.
Specifically look at the startup code for the application where CurrentCulture is modified for the CurrentThread.
Do not feel locked out of using per-culture resources by WPF. Different resources can be used via the "PublicResXFileCodeGenerator" as described in the article.
The MSDN Docs - CultureInfo.CurrentCulture Property may help.

USE of XAML not related to WPF or silverlight

I am trying to understand the use of XAML instead using it as markup in creating WPF and silverlight applications. Where else could i use XAML. Please provider all the possible uses of XAML.
Could XAML be used as regular XML to provider mapping and related stuff?
Please provider some links where i could learn about XAML.
Thanks.
This writeup can be helpful: http://www.davidpoll.com/2010/07/25/to-xaml-with-love-an-experiment-with-xaml-serialization-in-silverlight/. This article describes a way on how XAML can be used as a serialization format not just for a user-interface, but also for other CLR objects.
XAML is used as the serialization mechanism for workflows in Windows Workflow Foundation (WF), see for example http://www.codeproject.com/KB/WF/XAML_WF.aspx
XAML's a fairly efficient XML serialization format with hooks for namespaces and markup extensions. You don't have to use it purely for WPF applications; as long as the types you're serializing have parameterless constructors you can represent just about any .NET reference type in XAML.
If you're not using markup extensions, it's not really a huge leap past ordinary XML serialization. But the incremental improvements that it offers are useful enough, and the fact that it's a format supported by VS and WPF and Blend certainly doesn't hurt.

What is the best way of localization LOCBaml or Resx based localization?

I came through this What is the best way to localize a WPF application, sans LocBAML? . But, this didn't answer what I'm looking for.
I'm creating a CustomControl in WPF. I would like to provide localization support. The control contains, images, strings etc.,
Any help would be greatly appreciated.
Thanks
I think the document linked in this post contains a lot of information about localization in WPF. In the end, it is up to you to decide which mechanism to use.
Since you are talking about a custom control, I would consider to give it a Culture dependency property which the consumer of your control can use to specify the desired culture. This way, the consumer can use your localized control, relatively independent of the localization strategy he/she chose.
I'd suggest using Resx, try integrating into a WPF application with the TranslationByMarkupExtension example. http://www.wpftutorial.net/LocalizeMarkupExtension.html
LocBaml was a very odd thing for Microsoft to put out there and isn't better, or even complete.

Should we use server generated XAML to deliver our Silverlight/WPF UIs?

Back in January 2009, Dino Esposito published an article on MSDN titled "Managing Dynamic Content Delivery In Silverlight". We are considering using an approach like this for an upcoming project and were wondering if anyone had any advice on whether this is a good approach. Are there any traps or pitfalls we should look out for? We currently use Prism and would need to look at how the two would live happily together.
Yes! This approach, in my opinion, is what makes Silverlight and WPF so incredibly powerful. I have done this in the past and it is AMAZING how well it works. Data binding and ViewModels make it especially easy to do. Even better is if you use the dynamic capabilities of C# 4.0 to push dynamic properties into your ViewModel that your View can bind to. In other words, you can push down dynamic values that your dynamic views can bind to.
When you get it all working, it is beautiful.
A bit of self promotion here, but my ViewModel base class has a lot of support for this type of dynamic data binding approach.
As far as doing this with Prism, you can take advantage of the modularity Prism that prisim was built with. You can override the RegionRegistry, for example, with one of your own that knows how to create the dynamic view given the region name.
Beautiful, Beautiful stuff here.

Localizing MVVM based WPF applications

What would be a good aproach to localize a MVVM based WPF allication that can change its language at runtime? Of course I could create a string property in the ViewModel for each and every string that is displayed somewhere in the View but that seems rather tedious to me. Is there a common approach/best practice for this?
Here's an excellent article about WPF localization. It deals with the Microsoft-supported localization technique, and a few alternative ones
I wouldn't recommend the "official" solution for localization... it's really a pain to use, it modifies you XAML (adds x:Uid attributes to every element that can be localized), and there are no good tools from MS to make it an easy solution. Good old resx localization is much easier to use, and integrates quite well with WPF with just a few tricks (namely, markup extensions and/or attached properties). Also, you can easily change the interface language at runtime thanks to the binding system.
WPF has a lot of support for localization. Perhaps you can leverage that? Unfortunately I think that changing the user interface language at run-time is somewhat difficult and you probably need to come up with your own scheme.
Also, as the view-model is UI agnostic I don't think storing user interface strings in the view-model is a good solution. These belong to the view.
Instead of having user interface strings in your view model, you can store them in the assembly's resources and access them directly from XAML, using x:Static:
<TextBlock Text="{x:Static props:Resources.MyLabel}"/>
The props namespace should refer to your assembly's Properties namespace:
xmlns:props="clr-namespace:My.Assembly.Properties"
You can use a Custom Markup Extension to lookup localized values and update them when the UI Culture changes.
Here's an example of how this might work:
<Label x:Name="lblResxHelloWorldMarkupExtension1Value"
Content="{res:Res Id=HelloWorld,Default=Hello#}"
Margin="{res:Res Id=HelloWorldMargin,Default=10}"
Width="{res:Res Id=HelloWorldWidth,
ResourceSet=WpfClickOnce.MyFormRes, Default=50}" />
This example is taken from the excellent WPF Localization Guidance authored by Rick Strahl and Michele Leroux Bustamante here: http://wpflocalization.codeplex.com/. Download the guide from this site where this technique is described in detail in document form and with a sample application.
Another nice advantage of this approach is that it works in the designer.
If you are almost interested on this topic you can have a look at my library that I'm developing on codeplex.
LocalizationLibrary: http://localizationlibrary.codeplex.com/
Here's a couple of articles that could be of interest:
Localizing WPF Applications using Locbaml
WPF Runtime Localization
Simple WPF Localization

Resources