Including WPF's namespace in an XSD - wpf

We have a custom XML schema that can contain chunks of XAML for defining WPF DataTemplates. I used Visual Studio 2010's "Create Schema" command to generate an XSD based on a sample document that uses our schema.
One of the first lines in the generated schema was this:
<xs:import namespace="http://schemas.microsoft.com/winfx/2006/xaml/presentation"/>
However, Visual Studio generates this warning for the line:
"Imported schema for namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation' was not resolved"
Does it need an XSD for Microsoft's presentation schema to work? If so, is there anywhere I can download WPF's XSD (I haven't found one with Google, yet). Is there another way around this?

If you use xs:import, and want to use that schema for validation, you will have to provide that (XAML) schema. This can be done in different ways: place file in a known folder, use URL, or load schemas one by one into .NET schema set.
Another option is to use xs:any to declare your chunks of XAML, then you will have option to validate it against XAML schema or not.

Related

How can I provide summary XML Code documentation within the XAML Editor?

I have created a set of converter classes (IValueConverter) which can be used in XAML code of WPF application. All classes are documented fully with XML code documentations: summary of the class and its both convert methods including the parameters.
Now I wonder why the Visual Studio XAML Editor does not show any of my documentations.
How can I provide documentation with IntelliSense when a developer uses the Converter resource types the ConverterParameter?
It would be useful when IntelliSence shows my comments when typing ConverterParameter=.
Is this possible? What do I have to do?
Conveter classes only a one example where I would like to provide documentation. For custom user controls I would like to do the same.
I uses Visual Studio 2015 and Visual Studio 2017.

WPF Form based on XSD

I am new in WPF and want to create a UI using XSD that autogenerates the controls.
See screenshot
Just write proper XSLT for your XSD.
XSD is valid XML so it can be parsed with XSLT to get any other document. Because XAML is valid XML it won't be so hard.
You can find examples of XLST transforming XML to HTML and start from them. It's easier and gives immediate feedback if your XSLT is good.
Here you can find whole project to convert XSD to HTML form.
EDIT:
As it was suggested you can load your XAML in runtime but I think more convenient and handy will be generating it at build step. See this answer and documentation to get more details.
Yes, XAML is valid XML and can be transform. But if You want transform and load in runtime You must read answer for this topic
You may use InfoPath to design a Form
with Your XSD as starting point
and save the design as Extract.
You will find a folder with InstanceSample, XSLT and XSD.

Extract string from labels in xaml to resource files

I can't find any method of extracting string values from xaml (Silverlight) to a resource file. Do I really have to do this manually?
If this is not supported in VS2010, are there any 3rd party tools which offers help on this issue?
Building and maintaining resource files for localization purposes is quite tedious if you have to do this manually.
This should do the trick: http://wpflocalizeaddin.codeplex.com/
XAML is just XML, so you can write an XML parser in a Winforms app to find all the strings.
We did away with the need for the resources using a different technique (based on attached properties):
Link: Localisation of Silverlight projects after completion

RIA Services - Two entity models share an entity name

I have two entity models hooked up to two different databases. However, the two databases both have a table named 'brand', for example. As such, there is a naming conflict in my models. Now, I've been able to add a namespace to each model, via Custom Tool Namespace in the model's properties, but the generated code in my Silverlight project will try to use both namespaces, and come up with this,
Imports MyProject.ModelA
Imports MyProject.ModelB
Public ReadOnly Property brands() As EntitySet(Of brand)
Get
Return MyBase.EntityContainer.GetEntitySet(Of brand)
End Get
End Property
giving me this exception:
'Error 1 'brand' is ambiguous, imported from the namespaces or types 'MyProject.ModelA,MyProject.ModelB'.
Has anyone had experience with naming conflicts like this using RIA services? How did you solve it?
Found the solution.
Unload the client (Silverlight) project.
Right click the unloaded project and edit the .csproj or .vbproj file.
Add <RiaClientUseFullTypeNames>true</RiaClientUseFullTypeNames> inside the <PropertyGroup> tag
Reload project. Do a full rebuild.
Now the generated code will use full type names (i.e., MyProject.ModelA.brand)

How do I get the Localizable property and support in my own design tool?

Overview
In another question, I asked about deploying localizations for some runtime compiled UserControl's. However, before I can get to deploying the localizations, I need a way of localizing the controls.
Background
The controls are created by our own WinForms-style designer (using .NET's support for design surfaces, etc.) and saved as a binary format that combines the CodeCompileUnit, resource resx, and user source into one file. These files are then compiled into an assembly as appropriate at runtime by another tool.
In order to localize these, we need to tell the designer and serialization that localizable property values are to be stored in the resources. The VisualStudio WinForms designer does this using an extension property called Localizable and an associated property for specifying the default culture. We need this property in our custom designer, if possible.
Constraints
We need our standalone designer tool that is easy to use for non-developer types as well as restricting certain actions so using a free edition of Visual Studio (i.e. C# Express) is not going to work (I've already pitched it and failed); therefore, any solution to how we localize these UserControl's needs to compensate for this.
Question
Can we get the Localizable support into our custom WinForms designer?
If yes, how?
If no, what alternatives are there to localizing our UserControl's? e.g. post-processing somehow, different file format, etc.
I'm not sure if I understood your question correctly.
Just check for the System.ComponentModel.LocalizableAttribute on all properties to (de-)serialize if your control is Localizable.
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
// Checks to see if the property needs to be localized.
LocalizableAttribute myAttribute =
(LocalizableAttribute)attributes[typeof(LocalizableAttribute)];
if(myAttribute.IsLocalizable) {
// Insert code for handling resource files here.
}
Since you decided to write your own designer you have to do this yourself.
You need to add a System.ComponentModel.Design.LocalizationExtenderProvider to your design surface.

Resources