Avalonia UI, background obscures what I drew at Render - avaloniaui

I created a custom control by inheriting UserControl and drew a rectangle at Render
public override void Render(DrawingContext context)
{
base.Render(context);
context.DrawRectangle(ThePen, TheBox);
}
The box was displayed but when I set Background in the XAML of the MainWindow, the background colour obscured the box (box was not visible). Can I make the the box shown on top of the background colour?

Related

UWP Light dismiss ContentDialog

Is there a way to make the ContentDialog light dismiss?, so when the user clicks on any thing outside the ContentDialog it should be closed.
Thanks.
By default, ContentDialog is placed in PopupRoot. Behind it, there is a Rectangle which dim and prevent interaction with other elements in the app. You can find it with help of VisualTreeHelper and register a Tapped event to it, so when it's tapped you can hide ContentDialog.
You can do this after calling ShowAsync outside ContentDialog code or you can do it inside ContentDialog code. Personally, I implement a class which derives from ContentElement and I override OnApplyTemplate like this:
protected override void OnApplyTemplate()
{
// this is here by default
base.OnApplyTemplate();
// get all open popups
// normally there are 2 popups, one for your ContentDialog and one for Rectangle
var popups = VisualTreeHelper.GetOpenPopups(Window.Current);
foreach (var popup in popups)
{
if (popup.Child is Rectangle)
{
// I store a refrence to Rectangle to be able to unregester event handler later
_lockRectangle = popup.Child as Rectangle;
_lockRectangle.Tapped += OnLockRectangleTapped;
}
}
}
and in OnLockRectangleTapped:
private void OnLockRectangleTapped(object sender, TappedRoutedEventArgs e)
{
this.Hide();
_lockRectangle.Tapped -= OnLockRectangleTapped;
}
Unfortunately ContentDialog does not offer such behavior.
There are two alternatives you can consider:
Popup - a special control built for this purpose, which displays dialog-like UI on top of the app content. This control actually offers a IsLightDismissEnabled for the behavior you need. Since the Anniversary Update (SDK version 1607) also has a LightDismissOverlayMode, which can be set to "On" to automatically darken the UI around the Popup when displayed. More details are on MSDN.
Custom UI - you can create a new layer on top of your existing UI in XAML, have this layer cover the entire screen and watch for the Tapped event to dismiss it when displayed. This is more cumbersome, but you have a little more control over how it is displayed

How to set background color of an image using draw2d?

I have drawn one rectangle by using RectangleFigure in draw2d. And I am able to
color the rectangle figure by calling rectangleFigure.setBackgroundColor.
Now the same way I want to color the Image also. For that I used ImageFigure in
draw2d and I gave the background color by calling ImageFigure.setBackgroundColor().
But it does not give any color for me. So How can I give the background color
to the image figure in draw2d?
RectangleFigure extends Shape which draws it's own background by default. ImageFigure directly extends Figure which will only draw the background if you set it as Opaque:
imageFigure.setOpaque(true);

How to Autofit the widgets in a view to variable window size automatically

I have an RCP application in which i changed position of the window(shell) and its size by overriding the postWindowCreate() method in ApplicationWorkbenchWindowAdvisor class, the widgets in the views are not fitted to the changed window size, to see all widgets either i have to maximize the window or move scroll bars of the view to see all the widgets inside the view, is it possible to auto-fit(show all widgets in the current window size without moving scroll bars or maximizing the window) the widgets in the view even if the screen size varies.
Usually, you change the size of the shell in WorkbenchWindowAdvisor.preWindowOpen(), not in WorkbenchWindowAdvisor.postWindowCreate():
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
#Override
public void preWindowOpen() {
final IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(800, 600));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
// configurer.setShellStyle(SWT.TITLE | SWT.RESIZE);
}
}
Likewise, you can set the window title and the style of the window.
The position of the window is usually best set in WorkbenchWindowAdvisor.postWindowCreate()...
If you must change the size of the window, then remember to call shell.pack()!

How to implement this using Windows forms?

I have two problems with my windows form in Visual Basic .NET 2008. If you have worked with sticky notes you will understand me better.
Now my problems:
If you look you'll see the background color of number 1 and 2 are
diffrent but both belongs to the same control. How is this possible?
In right bottom corner, there is something by which a user can resize the form.
How I can do this?
Item 1: I think you are referring to LinearGradient Brush-- look in the System.Drawing.Drawing2D class.
Item 2: They are drawing a resize handler. You can try using the ControlPaint.DrawSizeGrip method or draw your own.
Update:
Per your comments, you can look into Owner-drawing a Windows.Forms TextBox
You can draw a gradient background by overriding OnPaintBackground():
protected override void OnPaintBackground(PaintEventArgs e)
{
// set these to whatever you want
Color color1 = Color.LightBlue;
Color color2 = Color.DarkBlue;
using (Brush backbrush =
new LinearGradientBrush(e.ClipRectangle, color1, color2,
LinearGradientMode.Vertical))
{
e.Graphics.FillRectangle(backbrush, e.ClipRectangle);
}
}
You can show the size gripper by setting the form's SizeGripStyle to Show:
SizeGripStyle = SizeGripStyle.Show;
Or just set it in the designer.
EDIT: Look at this page for creating a transparent textbox (if the textbox is transparent, the gradient form background will show through.)

how to use a flash movie as a background image of a vb.net form

I want to put a flash movie in my vb.net form as a form background. i want controls like buttons and labels on top of that flash movie. If this is possible then please provide a step by step answer. Thank you
If you have flash installed.
Right click on the visual studio toolbox > choose items .. when the dialog appears click on the COM components tab and scroll till you find the "Shockwave Flash Object" , tick the checkbox to add it to your toolbox.
Drag the control from your toolbox to your form ... set its "Movie" property to absolute url of your flash swf file.
you can now drop controls on top of the shockwave flash control (your flash movie host).
You might need to drag the control to fill up the available form size.
To disable the flash menu you could put a Panel above the Shockwave Flash Object and make the panel transparent ... but the usual way won't work properly.
Code below is gotten from this link
public class TransparentPanel : Panel
{
public TransparentPanel()
{
}
protected override CreateParams CreateParams
{
get
{
CreateParams createParams = base.CreateParams;
createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
return createParams;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Do not paint background.
}
}
Add that to your project and make the panel you add an instance of this class you'll get a transparent overlay on the shockwave flash object that disables the right click on any other mouse events.
Hope this helps.