How to add at run-time component (Compact Framework 3.5)? - compact-framework

I need to add at run-time component of the PictureBox.
There will be a few to several. How can I do it?
Programmers writing based on the Compact Framework 3.5.

You would do it the same way that all controls are added. In general it looks like this:
var newControl = new Control(); // or new PictureBox
// initialize properties like size, position, etc
myForm.Controls.Add(newControl);
A good way to see how this is done for different controls is to look at the designer-created conde for InitializeComponents, as it creates all of the controls and layout done in the designers at run time.

Related

Trouble plotting with ILNumerics in LinqPad - ILPanel think it is in design mode

I'm having some trouble using ILNumerics in LinqPad. I have the following code in LinqPad:
void Main()
{
var scene = new ILScene {
new ILPlotCube(twoDMode: false) {
new ILSurface(ILSpecialData.sincf(40, 60, 2.5f)) {
Wireframe = { Color = Color.FromArgb(50, Color.LightGray) },
Colormap = Colormaps.Jet
}
}
};
scene.First<ILPlotCube>().Rotation = Matrix4.Rotation(new Vector3(1f, 0.23f, 1f), 0.7f);
scene.Camera.Add(new ILSphere());
var panel = new ILPanel { Scene = scene };
PanelManager.DisplayControl(panel);
}
This code results in a big blue circle (with the text "ILNumerics ILPanel (OpenGL)" in the center) in the "custom" linqpad tab. The "Results" tab in linqpad contains the following text:
Determining Design Mode...
Entry Assembly: (null)
CurrentTypeAssembly: ILNumerics32, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null
Loaded Assemblies:
Design Mode: True
Questions:
Is possible render this as a WPF element instead of a WinForms control? (I guess this will render the plot successfully)
Alternatively; is it possible to "trick" the ILPanel to think it isn't being rendered in design mode?
1) ILNumerics targets Winforms only. But you may try to use a WPF WindowsFormsHost container? I don't have any experience with it and do not expect an improvement for your situation though.
2) The way ILNumerics is checking DesignMode right now: if the executing assembly (ILNumerics.dll) is not in the list of references of the entry assembly (LinqPad), DesignMode is considered. Therefore, I can see 2 "tricks":
Make LinqPad depend on ILNumerics. Probably not the best solution though.
Patch ILNumerics: Alter the helper method refered to by Joe Albahari to return false instead.
The second "trick" may could lead us to a future solution. I don't know, if the "normal" DesignMode property does work in conjunction with LinqPad either? Maybe we could combine the existing method with a settings switch for all uncommon cases.
Yes, you can render WPF controls in LINQPad - either by using PanelManager.DisplayWpfElement (or just by dumping it).
I don't think it will help you though, because ILNumerics uses Windows Forms only. It doesn't reference any of the WPF libraries.
I don't know whether it's possible to trick ILNumerics into thinking it's not in design mode. Take a look in Reflector at ILNumerics.Drawing.ILHelper.IsDesignMode. It's doing something dodgy with referenced assemblies. I don't know why they don't just check the control's DesignMode property - that's the normal way of doing it.

Source code for WinRT UI controls publicly available?

Is the source for Windows Store (WinRT) UI controls publicly available? We would like to extend some of the controls and not have to start completely from scratch, like we can for SL and WPF. Googling and looking through SO doesn't turn up anything for Windows 8.
Thanks!
So unlike WPF, [WinRT-XAML] controls are written in C++/CX.
But, it sounds not so much like you want the source code as much as you want to derive from existing controls and extend or override their functionality. You know you can do this, right? It's easy enough and sounds like you will get the results you are asking in your question.
Something like this:
public class MonkeyTextBox : TextBox
{
public new string Text
{
get
{
return "Always Monkeys!";
}
set { /* do nothing */ }
}
}
This is my custom TextBox wherein I have replaced the base implementation of Text with my own. Granted, I hope your custom controls are better. Anyway, you can do this with almost every control, and you can add your own properties and events. Make sense?
Reference: http://blog.jerrynixon.com/2013/01/walkthrough-custom-control-in-xaml-isnt.html
But to answer your question: no, we have not released the source (yet). Hopefully, that will save you the time looking for it. Maybe someday we will - maybe.
Best of luck!

How efficient is XAML parsing in WinRT / Win8?

When creating UserControls, it looks like the XAML is being parsed every time the control is initialized.
For example, when I create a UserControl, there's auto-generated code to initialize the component that looks like this:
public void InitializeComponent()
{
if (_contentLoaded)
return;
_contentLoaded = true;
global::Windows.UI.Xaml.Application.LoadComponent(this, new global::System.Uri("ms-appx:///Views/MyView.xaml"), global::Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);
}
This existed in Silverlight as well.
Creating the control once or twice is not a big deal, but if I have a large visual tree in each UserControl with Visual-States and bindings, and I'm creating it many times per application lifecycle, it would make sense to build the visual controls using C# to boost performance.
So, my question is:
Does the parser/framework "remember" the XAML file and avoid re-parsing it again on subsequent calls? That is, does it create a binary representation of the XAML so it doesn't have to read text all over again?
It's my understanding that XAML gets compiled into a binary form as a resource within your application. The runtime does not have to parse the text of the .xaml file, just as it does not have to parse your .cs code files.
The performance of instantiating the classes as declared with XAML is supposed to be on par with creating it in code.
Windows 8.1 xaml finally added XAML binary format :)
XAML Binary Format: The final signed appx will no longer contain text based markup as it will get converted into Binary.

Find out Easing Functions for WinRT Theme Animations

A slightly odd question, but is there anyway to find out what easing functions are used in the WinRT XAML Theme Animations - more specifically I'm trying to replicate that of the EntranceThemeTransition (which I can't use directly).
I naively thought using something like .NET reflector would help, but I'd gather I'd need the actual source code rather than what .Net Reflector shows.
Anyone any ideas?
You might like to take a look at the AnimationMetrics sample on MSDN.
There is an AnimationDescription class that will tell you all sorts of info on the built in animation types, basically anything in the Windows.UI.Core.AnimationMetrics.AnimationEffect enum.
For example:
var animationDescription = new AnimationDescription(AnimationEffect.EnterPage, AnimationEffectTarget.Incoming);
var s = new System.Text.StringBuilder();
s.AppendFormat("Stagger delay = {0}ms", animationDescription.StaggerDelay.TotalMilliseconds);
s.AppendLine();
s.AppendFormat("Stagger delay factor = {0}", animationDescription.StaggerDelayFactor);
s.AppendLine();
s.AppendFormat("Delay limit = {0}ms", animationDescription.DelayLimit.TotalMilliseconds);
s.AppendLine();
s.AppendFormat("ZOrder = {0}", animationDescription.ZOrder);
s.AppendLine();
s.AppendLine();
//etc
Link: http://code.msdn.microsoft.com/windowsapps/Animation-metrics-sample-acb0220c
I believe these built in animations are implemented in a different way and they run independently from regular Storyboard + child animations, so you would need to approximate these with some tests that compare these with regular Storyboard animations that you implement running side by side.
One way to visualize easing functions is to run a theme transition moving a UI element in one axis while you run another one that moves the element in a perpendicular axis in a linear motion (with no easing function applied).

Library for using SVG in Windows Forms / WPF?

Are there any libraries which
Allow to draw svg direct to a Windows Forms application
to a WPF application
I draw graphics and design everything with Inkscape, because I love that program.
Then I have those stunning svgs and have to either export them to png (WinForm) to use them or convert them to xaml-code (WPF) (Kaxaml helps me).
Is there a way to directly use my svgs?
Wow, I just read that Inkscape supports saving as XAML. I didn't realize that up to now shame.
But that still doesn't solve my problems with WinForms...
I personally hate how there's no native support for SVG in Microsoft's products/development tools. I've found two fairly complete but still immature SVG libraries that seem to be active as of this writing, definitely in need of contributors though.
WPF : Svg2Xaml (open source)
WinForms : SVG rendering engine (open source)
IIRC both libraries output a Drawing object which can be used directly through the Image class; You'll figure it out, they're both pretty straightforward to use.
If you want to load them directly into WPF,
I got better results from: https://github.com/ElinamLLC/SharpVectors
Yes, you can use ReaderSVG from AB4D to get WPF directly from XAML.
Regarding WinForms, removed a previous link to Kent Boogart's example as it was deleted sometime in 2019.
Copy below from this dotnetways post
To host a WPF control or WPF user control (wpfControl in this example) into Windows Form application, create an instance of ElementHost Class and add your WPF control/user control as child to the instance of ElementHost.
using System.Windows.Forms.Integration;
//Assembly: WindowsFormsIntegration (in WindowsFormsIntegration.dll)
//...
ElementHost elementHost = new ElementHost();
elementHost.Dock = DockStyle.None;
elementHost.Child = wpfControl;
Now, add the instance of ElementHost to a container control in your windows form (for instance containerPanel here)
containerPanel.Controls.Add(elementHost);