Drawing control to memory (Bitmap)

As the control has no parent container, you need to call Measure and Arrange in order to do a proper layout. As layout is done asynchronously (see Remarks in Measure and Arrange), you may also need to call UpdateLayout to force the layout to be updated immediately. public BitmapSource RenderToBitmap(UIElement element, Size size) { element.Measure(size); … Read more

How to embed the GNU Octave in C/C++ program?

Something like this embed.cpp #include <iostream> #include <octave/octave.h> int main(int argc,char* argv) {   int embedded;   octave_main(argc,argv,embedded=0);     return embedded; } Then mkoctfile embed.cpp –link-stand-alone -o embed in order to make a standalone executable. To call octave functions whether they are provided by scripts or octaveforge modules you can then use feval which takes the octave function name as … Read more

How to get all children of a parent control?

If you only want the immediate children, use … var children = control.Controls.OfType<Control>(); … If you want all controls from the hierarchy (ie, everything in the tree under a certain control), use a pretty simple data-recursive method: private IEnumerable<Control> GetControlHierarchy(Control root) { var queue = new Queue<Control>(); queue.Enqueue(root); do { var control = queue.Dequeue(); yield … Read more

WPF Tab Key Navigation

WPF treats the entire UI Tree as a single Tab scope. It isn’t broken up into smaller areas such as you would expect. This includes controls inside UserControls. For example, if you had <StackPanel> <TextBox Name=”TextBox1″ /> <MyUserControl /> <TextBox Name=”TextBox3″ /> </StackPanel> And MyUserControl looked like <MyUserControl> <TextBox Name=”TextBox2″ /> </MyUserControl> The default tab … Read more

WPF ComboBox without drop-down button

It’s possible, but you would need to retemplate it to achieve perfection. You can get most of the way there by overriding a system parameter as follows: <ComboBox xmlns:sys=”clr-namespace:System;assembly=mscorlib”> <ComboBox.Resources> <sys:Double x:Key=”{x:Static SystemParameters.VerticalScrollBarWidthKey}”>0</sys:Double> </ComboBox.Resources> <ComboBoxItem>One</ComboBoxItem> <ComboBoxItem>Two</ComboBoxItem> <ComboBoxItem>Three</ComboBoxItem> </ComboBox> However, it isn’t perfect because the focus rectangle still assumes there is a drop-down button present.