AvalonEdit (C#) Custom attributes in XSHD files - c#

I'm working on highlighting a small scripting language (that is not a derivative of any of the built in's) and I had a custom XML file setup for different syntax keywords and such.
I would really like to use the XSHD system that exists in AvalonEdit for loading custom keywords, but I need to have custom attributes in them.
So basically, after a lot of searching through the source code, I could not really pin-point the file that reads and specifies the keywords and rulesets.
Does anyone here know where I can edit the needed class to read some custom attributes and storing them?
I have all the XSHD and higlighting stuff in AvalonEdit down and working, so it's not using it that is the problem, per say, it's more the problem of using custom attributes in the keywords collection of the XSHD file.
In example:
<Keywords>
<Word defaultValue="hello" requiresShader="shadertype1, shadertype2" someCustomAttr="value">wordname</word>
</Keyword>
So, I need to set some custom properties to the parser of the XSHD file to load these custom attributes and store them in a custom class I have made that handles a few logical components that are crucial to what I'm trying to do.
I already have a working parser that parses a XML file of all my keywords and their properties (but I wrote it to ScintillaNET, but found AvalonEdit afterwards, that works better with WPF and such).
I will edit the original post with this information, sorry about possible misinformation.
Thank you

To load an XSHD file, you need to import the following libraries:
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
And then wherever you create the text editor (omit the first line and just reference the TextEditor if you create it in XAML), use the following code to load def.xshd.
// TextEditor is an AvalonEdit.TextEditor
TextEditor edit = new TextEditor();
XmlReader reader = XmlReader.Create("def.xshd");
edit.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
A good sample xshd file that I am using for a language in the works is this:
<SyntaxDefinition name="XAPL"
xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="Comment" foreground="Green" />
<Color name="String" foreground="Pink" />
<Color name="Xml" foreground="Orange" />
<!-- This is the main ruleset. -->
<RuleSet>
<Span color="Comment" begin="//" />
<Span color="Comment" multiline="true"
begin="/\*" end="\*/" />
<Span color="String">
<Begin>"</Begin>
<End>"</End>
<RuleSet>
<!-- nested span for escape sequences -->
<Span begin="\\" end="." />
</RuleSet>
</Span>
<Span color="Xml" multiline="false">
<Begin>spaz</Begin>
<End>spaz</End>
</Span>
<Keywords fontWeight="bold" foreground="Blue">
<Word>dealwith</Word>
<Word>import</Word>
<Word>end</Word>
<Word>var</Word>
<Word>default</Word>
<Word>template</Word>
<Word>sub</Word>
<Word>category</Word>
<Word>if</Word>
<Word>otherwise</Word>
<Word>and</Word>
<Word>xor</Word>
<Word>string</Word>
<Word>int</Word>
<Word>convert</Word>
<Word>to</Word>
<Word>escape</Word>
<Word>native</Word>
<Word>loop</Word>
<Word>is</Word>
<Word>to</Word>
<Word>from</Word>
<Word>by</Word>
</Keywords>
<!-- Digits -->
<Rule foreground="DarkGray">
\b0[xX][0-9a-fA-F]+ # hex number
| \b
( \d+(\.[0-9]+)? #number with optional floating point
| \.[0-9]+ #or just starting with floating point
)
([eE][+-]?[0-9]+)? # optional exponent
</Rule>
</RuleSet>
</SyntaxDefinition>

Related

How do I allow decimals to be copied into Infragistics Grid using clipboard operations?

I have a WPF project with an XamDatagrid that utilizes clipboard operations. I am currently allowing a user to paste a decimal into the grid, but when the user pastes in a decimal with a comma - example: 1,234.987 - I get an error saying "Unable to convert the value to the destination type, value 1,234.987 is not a valid number". However, when pasting in 1234.987, I have zero issues. How do I allow for the comma???
<igDp:XamDataGrid.FieldLayouts>
<igDp:FieldLayout >
<igDp:FieldLayout.Fields>
<igDp:Field Name="Field1" Label="Field1" Width="100" AllowEdit="False"></igDp:Field>
<igDp:Field Name="DecimalField" Label="DecimalField" Width="100*">
<igDp:Field.Settings>
<igDp:FieldSettings
EditAsType="{x:Type sys:Decimal}">
<igDp:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamMaskedEditor}">
<Setter Property="Mask" Value="99999.999" />
</Style>
</igDp:FieldSettings.EditorStyle>
</igDp:FieldSettings>
</igDp:Field.Settings>
</igDp:Field>
</igDp:FieldLayout.Fields>
</igDp:FieldLayout>
</igDp:XamDataGrid.FieldLayouts>
Your mask ("99999.999") is such that you are just specifying optional numeric digits but that doesn't mean as a whole it's a number so when you paste the editor just applies the characters in the text coming from the clipboard to the mask characters and since the ',' doesn't fit/match it's an error. It would be better if you used the n's to specify that it's a numeric section (of a specific size). e.g. "nnnnn.nnn". When you do that the paste works because it will ignore/skip digit grouping symbols like the ','. See the masks help for more on those characters.
Unrelated to this I would highly suggest you change your field to be the specific editor type so you can set properties on it without needing to use a style. In this way you also won't step on any styling that might be provided for that element if you were to set the Theme.
e.g.
<igWpf:MaskedTextField
Name="DecimalField"
Label="DecimalField"
Width="100*"
EditAsType="{x:Type sys:Decimal}"
Mask="nnnnn.nnn">
</igWpf:MaskedTextField>
Also you might get quicker support if you post on the Infragistics forums directly.

Span-Elements in FormattedString appear to be trimmed

I am trying to put some formatted text in a view (an imprint, for what it's worth) with a Label with an formatted text. Text formatting works as intended, but whenever I try to add whitespace characters to the end of a span element within the formatted text these appear to be trimmed. This holds true for normal spaces, non-breaking spaces and CR/NL so far. Anyway, when in the middle of a string, nothing is removed.
This renders the label unusable for me (at least for this use-case), since I won't be able to format my text properly. Is there anything I have missed? I did not find anything about this matter in the web and in the documentation. Is the approach taken completely wrong, or is this a bug in Xamarin? (For that matter, the version used is 2.3.2.127)
This renders the label unusable for me (at least for this use-case), since I won't be able to format my text properly
It's not entirely clear why you would try to achieve this formatting with trailing whitespace.
Have you tried using margin or padding around the label?
https://developer.xamarin.com/guides/xamarin-forms/user-interface/layouts/margin-and-padding/
Using whitespace characters for element spacing is generally not a good practice.
The solution to this is to use inline Text="..." rather than enclosing the text between an opening and closing tag. For example, this preserves the spaces:
<FormattedString.Spans>
<Span Text="You have " />
<Span Text="{Binding Points}" />
<Span Text=" points." />
</FormattedString.Spans>
But this trims whitespace:
<FormattedString.Spans>
<Span>You have </Span>
<Span Text="{Binding Points}" />
<Span> points.</Span>
</FormattedString.Spans>

How can one set minimalist interface of Excel with C#?

Using C#, I'm writing a program that has to use Excel only in order to edit some tabular data provided by my program. My program just creates an Excel application (the Microsoft.Office.Interop.Excel.Application object), creates within it a workbook, creates a worksheet, puts the data in Excel, and, after this, allows to a user to edit these data. The edited data can be easily read by my program. That's, in principal, all what I need from Excel.
This, therefore, means that a user of my program should not be able to format data in Excel, save an Excel file to the hard drive, open Excel files, and so on and so on. A user even does not need the Excel ribbon. Working with formulas is also does not required. Hotkeys (like "Ctrl + B" making the font bold, "Ctrl + S" saving the file, and so on) should be also not workable.
My question is: Is there a way to simply set such a minimalist interface for Excel? Or I should disable any aspect mentioned above by hand, step by step (disable the ribbon, switch off the hotkeys ans so on)?
When working within a VSTO project, you can disable most/all of the UI by using a custom ribbon XML file (there is a visual designer too but I doubt it would be sufficient for this).
To remove things, add a section for what you're removing, and set visible="false" or enabled="false" (users could still potentially add it back to the ribbon, but disabling it makes it grayed out).
e.g.:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<commands>
<command idMso="Cut" enabled="false" />
</commands>
<ribbon>
<tabs>
<tab idMso="TabHome" visible="false" />
</tabs>
</ribbon>
<contextualTabs>
<tabSet idMso="TabSetDrawingTools" visible="false" />
</contextualTabs>
<backstage>
<tab idMso="TabInfo" visible="false">
</backstage>
<contextMenus>
<contextMenu idMso="ContextMenuText">
<!-- you can't hide a context menu entirely, you have to hide each item -->
<button idMso="FontDialog" visible="false" />
</contextMenu>
</contextMenus>
</customUI>
This may also be possible if you're working with Office in the way that you seem to be, I don't really know.

Starting an app from another app

I have two problems:
I need to start an app from another app.
I need to make two certain image links do just one action each (right now, both of them do both action).
Details for no. 1: i've directly called Process.Start("D:\\proba/ControlsBasics-WPF.appref-ms");
What do I do when I move the app or instal it on a different computer and the respective user does not have that pathway? I want to make a connection between two apps.
Details for no.2: right now, I have two image links (pic2) that open both a main window and an article . I need to make one of them open the main window and the other one open the article. I've done a printscreen so that you can see the codelines for the image links.
This is a very important problem for me and I hope I was clear enough.
Thank you.
http://i.stack.imgur.com/x3fVi.jpg
I've also added the code so that you can see it better:
<List x:TypeArguments="mskbm:ExperienceOptionModel" xmlns="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:mskbm="clr-namespace:Microsoft.Samples.Kinect.InteractionGallery.Models;assembly=InteractionGallery-WPF" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<mskbm:ExperienceOptionModel
Name="VIDEO"
ImageUri="pack://application:,,,/Content/HomeScreen/01.png"
OverlayImageUri="pack://application:,,,/Content/HomeScreen/play-overlay.png"
NavigableContextName="Video"
NavigableContextParameter="Content/Videos/K4W.wmv" />
<mskbm:ExperienceOptionModel
Name="VIDEO"
ImageUri="pack://application:,,,/Content/HomeScreen/02.png"
OverlayImageUri="pack://application:,,,/Content/HomeScreen/play-overlay.png"
NavigableContextName="Video"
NavigableContextParameter="Content/Videos/K4W_NISSAN.wmv" />
<mskbm:ExperienceOptionModel
Name="MAPPA PUNTI VENDITA"
ImageUri="pack://application:,,,/Content/img/03.png"
NavigableContextName="PannableContent"
NavigableContextParameter="pack://application:,,,/Content/PannableContentScreen/WorldMap.xaml" />
<mskbm:ExperienceOptionModel
Name="TUTORIAL KINECT"
ImageUri="pack://application:,,,/Content/img/05.png"
NavigableContextName="Article"
NavigableContextParameter="pack://application:,,,/Content/ArticleScreen/Article2.xaml" />
<mskbm:ExperienceOptionModel
Name="CATALOGO INTERATTIVO"
ImageUri="pack://application:,,,/Content/img/01.png"
NavigableContextName="Article"
NavigableContextParameter="pack://application:,,,/Content/ArticleScreen/Article2.xaml" />
<mskbm:ExperienceOptionModel
Name="INFO E CONTANTI"
ImageUri="pack://application:,,,/Content/img/06.png"
NavigableContextName="Article"
NavigableContextParameter="pack://application:,,,/Content/ArticleScreen/Article2.xaml" />
</List>

WPF: how to set infinity symbol as content for a label?

I have a label. As the content I want to set the infinity symbol. How can I achieve that?
<Label Content="∞" ... />
FYI: XML Character Entities and XAML
Like this:
<Label Content="∞"/>
The infinity symbol is represented by the unicode character 221e. If you follow the link it shows fonts that support the character. It seems like most popular fonts do, including Arial, which I think is the default font for labels.
Somethig like this (might need to specify size of the image):
<Label>
<Label.Content>
<Image Source="URI to Image"/>
</Label.Content>
</Label>
Edit: Since you posted a picture i assumed you have an image, if you want the symbol as text say so.
See here: http://www.fileformat.info/info/unicode/char/221e/index.htm

Categories