Archive
HowTo: Insert new line and spacing at content of WPF TextBlock control
While adding more voice commands at SpeechTurtle, I had to update the active legend where the available commands are displayed and their text is highlighted as the respective commands are recognized by the speech recognition engine (using .NET’s managed Speech API).
A problem I faced was how to add a newline and prefixing the 2nd line with some spaces to align with the first command at the 1st line…
First of all, adding a new line was easy, inserted a <LineBreak /> tag in the XAML inside the TextBlock tag’s content, as shown in the screenshot below:
Then I had the issue that I needed to add some spacing so that “Pen up” at the 2nd line starts exactly under the start of “Forward” at the 1st line (see screenshot above)…
Tried to add a Run tag, with its Text set to some spaces, but couldn’t get an exact positioning:
So I tried using a Separator instead, since I could define a Width for it, however, it was drawing as a gray line:
So I either had to change its color to White or Transparent, or use a Null Foreground Brush on it (one difference of a Null brush from a Transparent one is that the element ignores Mouse events in that case from what I remember), or just set its Visibility mode to Hidden:
Do note that WPF has another visibility mode apart from Visible and Hidden, that is Collapsed, where the respective control disappears from the layout flow (that value is not supported in Silverlight from what I remember), which is not what we wanted in this case (Hidden was the correct option to choose):
Suggestion: Case adaptive text replacement in Visual Studio editor
Have again suggested this long before to Visual Studio team, but since Visual Studio 2013 has a “Send a Frown” feature, I’ve sent it again with some suggestions on how it could be implemented.
I need some clever replace in cases like that one shown in the screenshot below, where I have the implementation of a Sounds property and want to clone that and rename it to Music (this is useful when repeating a coding pattern, but more importantly can use this when refactoring code and need to rename something).
When doing replace on the selection, replacing "sounds" to "music", I want the word/target phrase to detect the casing of the source word/phrase and keep the same casing style, that is:
– IsSoundsOn should become IsMusicOn
– soundsOn should become musicOn
– PROPERTY_SOUNDS should become PROPERTY_MUSIC
As you can understand now I have to do 3 replacement operations, having selected the option "Case sensitive":
– Sounds to Music
– sounds to music
– SOUNDS to MUSIC
I’d rather have an option "Case adaptive" or something like that (marketing people might call this "Smart replace").
Implementation-wise, every time it detects the source text (case insensitive search), it would check if it is found in one of the following casings:
– first letter non-capital
– first letter capital
– all letters small
– all letters capitals
and when replacing with the target text it would apply the same casing state to it (affecting just the first letter of the target or all letters depending on which of the above casing states were detected for the source string at each position it was found in the source text)
HowTo: Tell IE to use compatibility mode without editing your web pages
one reads:
We are using Telerik’s rich text editor (RadEditor), and it seems that RadEditor has specific behaviour regarding insertion of break tags.
To circumvent this issue please try to add host header in ISS 7 (website level):
Name = "X-UA-Compatible"
Value = "IE=EmulateIE10"Or, you can insert Html Meta tag on a PreRender event (of Page that uses RadEditor):
HtmlMeta meta =
new
HtmlMeta();
meta.Attributes.Add(
"http-equiv"
,
"X-UA-Compatible"
);
meta.Attributes.Add(
"content"
,
"IE=EmulateIE10"
);
Page.Header.Controls.Add(meta);
This is a very handy trick, one can open up a website at IIS console and open HTTP Response Headers node and then add the Name / Value pair X-UA-Compatible / IE=EmulateIE10 to force say Internet Explorer 11 to behave like Internet Explorer 10
To confirm it works, press F12 to show developer tools in IE11 and see at the right that it says “IE10” instead of “Edge” at the HTML engine selection dropdown list (compatibility mode).
HowTo: Code folding in NetBeans IDE source code editor
As explained near the end of https://ui.netbeans.org/docs/ui/code_folding/cf_uispec.html, the NetBeans IDE source code editor supports custom code folding tags for any language, like below (here defining the code folding tag in a Java comment, obviously need to use specific comment syntax for the respective language).
// <editor-fold desc="isUserStudent"> —————————————-
public static boolean isUserStudent(PortletRequest request)
throws NamingException, PortletServiceUnavailableException, PumaException, SQLException
{
return isUserStudent(new DbAccess().getConnection(), request);
}public static boolean isUserStudent(Connection connection, PortletRequest request)
throws NamingException, PortletServiceUnavailableException, PumaException, SQLException
{
return !StringUtils.isNotPresent(getUserStudentId(connection, request));
}
public static boolean isUserStudent(int studentId, PortletRequest request)
throws NamingException, PortletServiceUnavailableException, PumaException, SQLException
{
return isUserStudent(studentId, new DbAccess().getConnection(), request);
}public static boolean isUserStudent(int studentId, Connection connection, PortletRequest request)
throws NamingException, PortletServiceUnavailableException, PumaException, SQLException
{
return (String.valueOf(studentId).equals(getUserStudentId(connection, request)));
}
public static String getUserStudentId(Connection connection, PortletRequest request)
throws NamingException, PortletServiceUnavailableException, PumaException, SQLException
{
return DbStudent.getStudentId(connection, Puma.getUserName(request));
}// </editor-fold>————————————————————-
This shows up in NetBeans like below when folded:
You can also optionally specify defaultstate="collapsed" at the code folding tag so that when the file is opened that region appears collapsed.
HowTo: Multi-row captions and wrapping at Silverlight Media Framework
One of the main goals of the ClipFlair project is to explore the use of Video Captioning (together with Revoicing) for Foreign Language Learning (FLL). There both are important enhancements compared to the simpler two-line subtitling that was put in use in its ancestor project LeViS.
Captioning means that multi-row text is needed while text wrapping is also useful, especially if cartoon-like balloons over the video area are to also be examined as an option. Implementing multi-row captions and caption wrapping was a bit tricky in the SMF based player, due to the lack of relevant documentation, so adding some relevant notes below.
As I discuss in more detail near the end of the discussiion at http://smf.codeplex.com/discussions/245424, the way I finally managed to make SMF player show multi-row captions is by setting the caption region bounds (via Origin and Extend properties of the CaptionRegion object) to take up nearly all the video area and combined it with DisplayAlign = DisplayAlign.After (to bottom align the caption rows group) and Overflow = Overflow.Dynamic (to extend the visible caption area dynamically inside the defined bounds).
Regarding caption wrapping there seems to be a bug in SMF, it wraps caption text at the video boundary instead of at the caption region max boundary (as defined by Origin/Extend properties of the CaptionRegion object). Have reported it at:
http://smf.codeplex.com/workitem/23634
A workarround for caption wrapping to work perfectly is to set top to 0 for the origin and set extend width to 100% for the caption region, but this won’t be useful if you want to show cartoon-like bubbles on the video for some captions. If Microsoft don’t fix that in the near future I guess I’ll have to fix it myself at the source-code of SMF (luckicly it’s an open-source project).
The relevant code snippet from http://ClipFlair.codeplex.com for the MediaPlayer component is:
private const double CAPTION_REGION_LEFT = 0; //0.05; private const double CAPTION_REGION_TOP = 0.05; private const double CAPTION_REGION_WIDTH = 1; //0.9; //SMF 2.7 has a bug here,
//it wraps caption text at the video boundary instead of at the
//caption region max boundary (as defined by Origin and Extend) private const double CAPTION_REGION_HEIGHT = 0.9; public static void StyleCaptions(CaptionRegion theCaptions) { if (theCaptions == null) return; theCaptions.Style.ShowBackground = ShowBackground.WhenActive;
//doesn't seem to work if other than transparent color is used theCaptions.Style.BackgroundColor = Colors.Transparent; //set caption region (max) bounds theCaptions.Style.Origin = new Origin() {
Left = new Length() {
Unit = LengthUnit.Percent, Value = CAPTION_REGION_LEFT },
Top = new Length() {
Unit = LengthUnit.Percent, Value = CAPTION_REGION_TOP } }; theCaptions.Style.Extent = new Extent() {
Width = new Length() {
Unit = LengthUnit.Percent, Value = CAPTION_REGION_WIDTH },
Height = new Length() {
Unit = LengthUnit.Percent, Value = CAPTION_REGION_HEIGHT } }; //theCaptions.Style.Direction = Direction.LeftToRight; theCaptions.Style.DisplayAlign = DisplayAlign.After;
//align multirow catpions to bottom of region theCaptions.Style.TextAlign = TextAlignment.Justify;
//horizontally center captions theCaptions.Style.WrapOption = TextWrapping.Wrap;
//wrap too long captions to next row theCaptions.Style.Overflow = Overflow.Dynamic;
//extends the area for the captions as needed, up to the given Extent foreach (CaptionElement caption in theCaptions.Children) StyleCaption(caption); }
public static void StyleCaption(TimedTextElement theCaption) { if (theCaption == null) return; theCaption.CaptionElementType = TimedTextElementType.Text; theCaption.Style.ShowBackground = ShowBackground.WhenActive; theCaption.Style.BackgroundColor = Color.FromArgb(100, 0, 0, 0);
//use a semi-transparent background theCaption.Style.Color = Colors.White; Length length = new Length { Unit = LengthUnit.Pixel, //must use this, since the default LengthUnit.Cell
//used at TimedTextStyle constructor is not supported Value = 20 }; theCaption.Style.FontSize = length; }
I also tried setting Padding property at the code above in case it would help with the correct wrapping, but it somehow results in crashing Silverlight (may be related to the fact that I have hardware acceleration enabled for our Silverlight app).
HowTo: Type in double-quote in Windows Live Writer
A big nuissance in Windows Live Writer is that when you try to type in a double-quote character you get some special Unicode character (“ or ”, at the start and end of a string respectively), other than the classic ASCII character used in programming.
That way people copy-pasting snippets from your blog can get lots of errors. I remember having that issue sometime ago with people copy-pasting (into a .reg text file) a registry script to add Google search engine into Copernic Agent from my blog and not understanding why it wasn’t working as expected.
However, I found a keyboard shortcut to work-arround this issue. You just press BACKSPACE key right after typing in a double-quote character in Windows Live Writer to restore it a real ASCII double-quote.
text transforms: TemplateFilter, TextCaseConvertion, CharConv, Dos2Unix, Unix2Dos, ClearTextFilter
Added various tools related to text transformations at my tranXform website (30-Sep-2010 update):
TemplateFilter
DOS filter – parses CSV-style multi-column (“;” separator) input text rows (one row per text line) and generates text based on a supplied template that is applied per input row
TextCaseConvertion
simple GUI-based tool to convert string to upper-case, lower-case and camel-case
CharConv
Windows and Microsoft Word GUI for Text transformation given character set mapping (from/to) and calculation of mapping given matching (portions of) source and target text
Useful for deciphering copy-pasted text from PDF documents that ends-up with strange character swaps in it due to encoding reasons
Dos2Unix
DOS filter – converts CRLF (Dos/Windows style) to LF (Unix style) for text ending line markers
Unix2Dos
DOS filter – converts LF (Unix style) to CRLF (Dos/Windows style) for text ending line markers
ClearTextFilter
DOS filter – converts control characters to space chars
Suggestion: triple-click to select row in InputBox/TextBox and paragraph in RichTextBox
In upcoming Internet Explorer version (IE9), one can triple click text in a webpage to select a whole paragraph (vs double-clicking that already existed to select a whole word) of text. A really useful feature I believe (if coupled with an accelerator to send selected content to social networks it would be even nicer)
I’d suggested this feature is added to Windows native UI controls too (and hope this would eventually be implemented in Java and .NET WinForms and WPF controls too). It would be very useful to have in single-line InputBox / TextField (instead of having to press CTRL+A) but especially in multi-line ones like the classic TextBox (where it would select current text row) or the RichTextBox (RTF-enabled) one (where it would select current paragraph as in IE9).