It is possible to export Microsoft Visio drawings as a Website containing Silverlight content. This is described on this blog-post.
The output of such an export are the following:
xaml_1.xaml (contains the structure of the control)
data.xml (contains all text content such as labels, etc)
several java-script files
*.htm pages with a Silverlight container
other files such as *.css and images
I would like to integrate the exported XAML code into another existing Silverlight application. I found this blog-post telling me how to load XAML code dynamically during runtime.
What I would like to know is how to "merge" the XAML-file and the data.xml and how I can get a reference to the items of the XAML code, in order to change certain texts...
In the associated xaml js file (eg xaml_1.js) there's a handleMouseUp function that reads the shape ID from the (XAML) 'name' string and then calls OnShapeClick in frameset.js. This method, which is common to all of the js-based Save as web output types, then calls other methods to populate the details table or retrieve hyperlinks found in data.xml. If you have a look at the FindShapeXML function in frameset.js you'll see that it gets the appropriate data based on the page and shape IDs (note that shape IDs are unique to a page as per Visio itself).
In terms of creating data-bound or dynamic shape text, one workaround for the glyphs issue that #slfan highlights is prevent the text from being output. For example, prior to running Save As Web in Visio, you could loop through all of the shapes and set their HideText ShapeSheet cell to true. This will prevent all of the glyphs xaml being generated and you'll still have access to the text string in data.xml. I guess you wouldn't then benefit from the correct font scaling, but it depends on your scenario. If it was really important to get the scale right then you could parse the RenderTransform attribute (which is described in attribute syntax rather than property element syntax) of the glyph elements.
Glyphs are there (I'm guessing) because it mirrors how Visio works in the application ie in Visio you can select individual characters within a shape's text and apply different fonts and formatting, but if you don't need that, I'd be tempted to ditch the glyphs collection and just use a TextBlock as #slfan suggests.
I think you have to tweak the generated XAML a little bit. Unfortunately Visio generates glyphs for every single character. If you want to change the text at runtime, you will have to remove this glyphs and add the required controls (e.g. TextBlock) yourself.
You can load the XAML into Silverlight with XamlReader.Load. A good description you find here: http://blogs.silverlight.net/blogs/msnow/archive/2008/10/09/silverlight-tip-of-the-day-60-how-to-load-a-control-straight-from-xaml.aspx.
All JavaScript and HTML files you can ignore, the XML-file you need to identify your controls. The ID's in the XML refer to the corresponding elements in the XAML-file.
Related
At run time I am capturing user inputs on basis of that I am creating a dynamic view in form of XAML, I need to render this XAML code on WPF UI
You have several options, depending on exactly what you want to do.
An uncompiled file can be transformed into one ui element using Xamlreader.Load.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.markup.xamlreader.load?view=netframework-4.8
https://www.c-sharpcorner.com/Resources/774/how-to-load-xaml-in-xamlreader.aspx
A String can be similarly transformed using xamlreader.parse.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.markup.xamlreader.parse?view=netframework-4.8
Once you have a control you can then use it. EG set the content of a contentcontrol to your control and it will appear.
You can also merge in an uncompiled resource dictionary. Which could have controls and or resources in them.
You can see a number of related techniques in the series of samples linked here:
https://social.technet.microsoft.com/wiki/contents/articles/28797.wpf-dynamic-xaml.aspx
I have a very large wpf project and after two years of development i requested to make it bilingual, is there any way to automatically extract strings in labels and grid headers in xaml files so i can translate them instead of manually extract them?
I don't know if there is any existing tool to help, but you can implement it yourself, I faced such a problem when I was converting a large solution of above 100 C++ projects from ansi to unicode strings, I implemented a simple tool with one window containing 2 rich edit boxes, one for the original text with replaces colored, and other for the replacement, for manipulating the resex files have a look at Working with .resx Files Programmatically, Don't forget that regular expression is your friend to accomplish this tool.
You can automate this process by finding all Label controls in WPG root Grid element (e.g. mainGrid) and extracting their content using the following C# code snippet:
IEnumerable<Label> _collection = mainGrid.Children.OfType<Label>();
foreach(Label _control in _collection)
{
string _text = _control.Content.ToString();
// add you code here
}
The results can be placed in Resource file (for example, CSV) with your translation added. Other solution (more sophisticated) pertains to the creation of multilingual XML file, or the local multilingual database with all label contents added to the first field, translation added to the next fields, etc.
Hope this may help.
Is there any way I can compare a word document(.docx) with a document template(.dotx) generated in microsoft word.
I want to do this comparison programmatically using c#.
I want to compare both documents word to word so that I can determine to which template the document belongs. I don't just want to compare the size of both but I want to compare the contents also.
By this comparison I want get the following results.
From which document template the document is generated.
In the document template, I want to check that at which place a particular information is stored.
Say for example I want to search for the communication information of a person, then I want to traverse the document and check that At which position the template has the area/section for Address.(i.e. Top left corner, top center, In a paragraph, In body etc)
In same way I want to extract other information too, Like Link to other documents etc.
After getting those positions I want to get that Information from the .Docx file.
Say, If I found that the Address in the top-left and there are five links referring to other documents in five different paragraphs. Then what I want is to get the Address and save it to a variable. After that I want to replace those link contents from placeholders to Actual hyperLinks. i.e If a Link is referring to Doc-A then Instead of just showing a Plain text I want replace it with A hyperlink to Doc-A.
Any suggestions?
Thank You.
Your question is rather too vague and involved to give a really good answer, however...
To find out from which template a document was generated the object model provides the property: Document.AttachedTemplate with will return the full file name. This is certainly better than comparing word-by-word (which is also very time-consuming)
The Word object model also provides the method CompareDocuments (belongs to the Word.Application class). This will "highlight" differences in the text content of two documents.
Links will be found in the Document.Hyperlinks collection
Getting the position of things is a bit chancy with Word and it depends on what you really mean by "top-left", etc. Better would be to construct the templates using content controls, form fields and/or bookmarks so that you can uniquely identify important sections. However, Word does provide the Range.get_Information method that can return relative and absolute positions on the page if that's what you really want.
I'm generating an MS Word document from user data. The data is placed in a container which is serialized to XML, and the resulting XML is converted to OpenXML using XSLT. There are a few minor changes done programmatically in C# to generate the Word document, as they can't be done with XSLT.
There is a user requirement that an item be placed completely on one page without any associated data being split onto another page. Sometimes one item will fill up an entire page, and sometimes I can fit three or four items on one page (I need to insert a separator (horizontal rule) between items that fit on the same page.)
Is there a way to determine whether or not one item or OpenXML paragraph will fit entirely on the "current" page? This can be either via C# or XSLT, and I can work something out.
Unfortunately, the only way this can be reliably done is to actually render the output, including all of the font sizes, bolding, kerning and all that. Which means you have to do the pagination in Word, and then save it back to the OpenXML.
I want to create a recipe application. I would like the input to look and feel like you are editing a document. If I were doing this in word, I'd create a template form for the user to use for the imput.
The form will look something like:
{Categoty} {Title}
{Image} {yield / nutrition info}
Ingredients
{bulleted list goes here}
Directions
{Numbered list goes here}
Notes / Comments
{Free form text goes here}
I tried doing this with a FlowDocument embedded im a RichTextBox, but could not figure it out. I can store the info and populate the FlowDocument parts easy enough, but I could not figure out how to control editing to force bullets or numbering at certain places / keeping the user from changing the format, etc.
Can this be done in a FlowDocument? If not, how can I create the bulleted / numbered list areas?
Flow Documents are editable as long as you use RichTextBox as opposed to Page.
you might want to take a look at this or this or even this
I ended up creating custom controls for the lists (custom grid supporting bulleted or numbered editable lists and using other controls for the various document parts to give me the control I want - I use an XML file for storing the pieces of the document and how to generate the FlowDocument (I hope this gives me the ease of updating the templates when I am asked to add something new)... I only generate a FlowDocument for printing purposes.
I did not get all the functionality I wanted, but I made it work. Now for my next project..