Apply stroke to a TextBlock (Windows 8) - c#

How do you apply stroke (outline around text) to a TextBlock in XAML in a Windows 8 store app (not WPF)?
A very similar question was asked in 2008, but the suggested solution from Apply stroke to a textblock in WPF and the referenced https://msdn.microsoft.com/en-us/library/ms745816.aspx only work on Windows Presentation Foundation (WPF) applications. The effect I am looking for is the same.
Thanks for your help!

I have successfully done it with Win2D effect http://expediteapps.com/blog/textblock-with-win2d-effects/
The idea is to apply two effects that create the outline effect. You can experiment with different ways and find the best combination you need. To add Win2D you can get it by nuget and is really easy to use.
and you do not need to convert the font to any strange glyphs.

Related

how to save Canvas as image in WINRT using c# [duplicate]

I am developing a paint like application in metro style with C#/XAML. I want to save whatever content is drawn on canvas as image. I have checked this solutions but it didn't helped me.
Save canvas to bitmap
http://blogs.msdn.com/b/saveenr/archive/2008/09/18/wpf-xaml-saving-a-window-or-canvas-as-a-png-bitmap.aspx
So how can I save the canvas content as image ? Please help me with sample coding.
The accepted answer from Sascha is no longer true for Windows 8.1. There is a new RenderTargetBitmap class that allows Rendered XAML to be converted to a bitmap.
See: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap.aspx
However I can't seem to render that XAML is Collapsed or otherwise not currently on screen. Any help with that would be appreciated!
It seems it is currently not supported out of the box like we were used to do it with WPF:
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/dd66c749-efed-4b55-a716-e0aa3a637d28
While when doing HTML5/Javascript Metro apps you can do this:
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/cf8c17dc-68d4-4777-951f-bb7f0665bd06
The standard approach in other xaml frameworks such as Silverlight and WP7 was to use WriteableBitmap, however the version in WinRT doesn't have a constructor that takes a xaml element which leads me to believe that it's currently impossible against the latest API.
Sorry I couldn't be more help/
One workaround is to use Direct2D with DirectWrite. It is a bit involved, but I might make a library available at some point.

Draw TextBox border as in Vista / 7

In Windows.Forms, I was not able to reproduce the exact same TextBox border as you see it in Vista / 7 Aero. All I get is a gray rectangle instead the slightly sunken gray / blue 3d border. I tried the following methods with no success:
VisualStyleRenderer class
TextBoxRenderer class
Control.DrawToBitmap()
P/Invoke with UxTheme and friends
Drawing RichTextBox elements instead of TextBox ones
This problem has already been discussed here but with no solution: http://social.msdn.microsoft.com/Forums/hu-HU/winforms/thread/46e66852-b52e-420d-8fe0-b717f86ecb18
It looks like there's no obvious solution for this problem.
Does anyone know how to draw the exact same border as in Aero?
It's probably not going to happen for you.
I think the VisualStyleRenderer, including the TextBoxRenderer, were more meant for the XP themes.
Even the Control.DrawToBitmap(...) function magically draws a different version from what is on the screen.
I don't have the canonical answer for this, but it's most likely a result of Microsoft moving on with WPF and leaving behind the WinForm controls with those visual themes half-baked.
The only answer to this question is to use WPF or use a 3rd party system like DevExpress (which support custom themes) if you need to "theme" all of your controls.

How to change background color of DateTimePicker control under Windows Vista / 7

My question is the same as the one at Changing the background color of a DateTimePicker in .NET. Unfortunately, the solution there doesn't work in Windows Vista/7 when visual styles are enabled. It does work fine if I disable visual styles, but that isn't an acceptable solution for my application.
How do I change the background color of a .NET WinForms DateTimePicker under Windows Vista / 7 when visual styles are enabled?
Any answers written from a C++ / Windows API perspective are welcome as well; I am experienced enough to translate a solution from one platform to another. I just ask it from a C# / WinForms perspective as there are a lot of developers who use it.
Edit: Also I should add that suggestions to owner-draw the entire control are at the very bottom of my possible list of solutions as it sounds like a ton of work. Existing efforts I've seen seem very incomplete.

How would one go about creating one’s own graphics effect in WPF?

I have an Image object in my application which the user can drag around. The object displays an image which is partly transparent, so the window background (which is itself a bitmap) can be seen through it.
I want to add a graphics effect to this object. Assume that I already have an algorithm for this effect — that’s not the issue. The issue is how to get this algorithm into WPF.
So I tried to look at how DropShadowEffect works, but the implementation displayed in Reflector is empty. I also tried to look at what methods from the abstract classes Effect and ShaderEffect I should override and there doesn’t seem to be anything related to actually rendering an effect.
So how do I create my own effect?
The best and fastest way is to use pixel shaders (supported starting with WPF 3.5 SP1 I think) . It will require some shader language (HLSL) knowledge, though :-)
Here is a tutorial: How Do I: Create Custom Pixel Shader Effects for WPF
a library on codeplex: Windows Presentation Foundation Pixel Shader Effects Library
an article with .NET 4 information (including Sliverlight support which has it too): SilverShader – Introduction to Silverlight and WPF Pixel Shaders
A very cool tool (and resource) is Shazzam it will help you to create the effects and it contains a nice tutorial.

How do I mimic the windows 7 UI?

I want to try and get the same look as Windows 7, with the aero glass dropping down just a little bit so that there can be a back button/address bar/ search box. Are there any tutorials on how to do this? I really need something simple, as I tried looking at a few other tutorials that try to explain how to use DWM with c# and I get totally lost.
Done as an answer :)
Absolutely use WPF, WinForms is a nightmare for this sort of thing. Combine it with http://code.msdn.microsoft.com/WindowsAPICodePack and you're on to a winner.
Ive been using the glass_full class from the site below on WinForms and and it works great.
http://www.dreamincode.net/forums/topic/146813-glass-form-dwmapidll-api/
I found a workaround for the black text issue with WinForms is to simply set backcolor and transparencyKey to a unused color.
(To prevent clickthrough, make sure the red and blue values are different, I use 221,222,223 as my color values so it gracefully fallsback to grey without Aero)

Categories