How would I animate a BlurEffect to any control? - silverlight-4.0

I would like a reusable function that simply does a BlurEffect on any particular valid Control type.
e.g.
var animation = new DoubleAnimation
{
From = 0,
To = 8,
Duration = new TimeSpan(0, 0, 0, 2),
AutoReverse = true
};
control.Effect = new BlurEffect();
// How to cycle the From and To on the Blur Radius?
I am uncertain how to dynamically create an animation in code behind to make this possible.

This article shows how to define an animation and story board in code.
You'd need to add the BlurEffect and use RadiusProperty of blureffect instead of RotateTransform.AngleProperty like this:
control.Effect.BeginAnimation(Blureffect.RadiusProperty, animation);
-edit-
I see now that you're using Silverlight, not wpf (where Effect implements IAnimatable)
i'll try and find a solution for silverlight
-edit2-
Have you seen/tried this? Msdn also has a sample for silverlight
-edit3-
Your direction got me towards the right answer which is as follows:
private void BlurSomething(FrameworkElement control)
{
var storyboard = new Storyboard();
var animation = new DoubleAnimation
{
From = 0,
To = 8,
Duration = new TimeSpan(0, 0, 0, 1, 0),
AutoReverse = true
};
var effect = new BlurEffect();
control.Effect = effect;
storyboard.Children.Add(animation);
Storyboard.SetTarget(storyboard, control.Effect);
Storyboard.SetTargetProperty(storyboard, new PropertyPath("Radius"));
storyboard.Begin();
}
It should be noted that Silverlight does not make animations as easy as WPF, but in the end this can be done.

Related

.NET MAUI : Override the default style of a windows view (TextBox)

I want to create a custom Entry with a completely personalized visual.
For this, I created a CustomEntryHandler to modify the native view of the windows platform but I can't override the basic windows style which imports some effects :
The background color that changes on over
The bottom border that is displayed when entry is focused
...
I think I understood that this style comes from the default style of windows, in the generic.xaml file.
Does anyone know how I can override this ?
protected override TextBox CreatePlatformView()
{
var nativeView = new TextBox();
nativeView.Margin = new Microsoft.UI.Xaml.Thickness(0, 0, 0, 0);
nativeView.FocusVisualMargin = new Microsoft.UI.Xaml.Thickness(0, 0, 0, 0);
nativeView.BorderThickness = new Microsoft.UI.Xaml.Thickness(0,0,0,0);
nativeView.Padding = new Microsoft.UI.Xaml.Thickness(0, 0, 0, 0);
nativeView.CornerRadius = new Microsoft.UI.Xaml.CornerRadius(0);
nativeView.Background = new SolidColorBrush(Colors.Transparent);
return nativeView;
}
Screenshot of the entry focused with code above
UPDATE 11/10/22 : I also want to remove the Clear button of the TextBox.
Thanks in advance.
The easiest way would be to write a new Style and apply it to your control using this code:
var nativeView = new TextBox();
nativeView.Style = Application.Current.Resources["MyCustomTextBoxStyle"];
In your App.xaml, you need to add the following style:
<Style x:Key="MyCustomTextBoxStyle" TargetType="TextBox">
<!-- Your textbox style -->
</Style>
You can find the standard WinUI 2 TextBox style here. If you would like to remove the clear button, you could remove the button that is part of the TextBoxStyle here.

The problem with the layout of checkbox when using BooleanFieldEditor

I am trying to use BooleanFieldEditor instead of Button with style SWT.CHECK. And I am getting the problem with layout of the checkbox.
The significant part of my previous code is:
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button checkBox = new Button(projectGroup, SWT.CHECK);
checkBox.setText(Messages.getString("WizardNewProjectCreationPage.createEmptyProject")); //$NON-NLS-1$
checkBox.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
Button button = (Button) event.getSource();
shouldEmptyProjectBeCreated = button.getSelection();
}
});
It gives me this result:
In this case the checkbox has a small indent at the top and the left side.
The significant part of my current code is:
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().extendedMargins(100, 0, 100, 0).spacing(100, 100).applyTo(projectGroup);
BooleanFieldEditor emptyProjectCheckbox = new BooleanFieldEditor("createEmptyProject",
Messages.getString("WizardNewProjectCreationPage.createEmptyProject"), projectGroup);
// GridDataFactory.defaultsFor(projectGroup).grab(true, false).span(2, 1).applyTo(projectGroup);
// emptyProjectCheckbox.fillIntoGrid(projectGroup, 1);
createEmptyProject = emptyProjectCheckbox.getBooleanValue();
Whatever values I set into extendedMargins() and spacing() methods, the result is the same - checkbox is located strictly at the level of the upper frame:
As you can see, in this case indents are smaller than on the first picture. I want to make the same indents as on the first image and want to understand, how to manage the location of BooleanFieldEditor's checkbox relatively to another elements.
Using second composite solves the problem:
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().extendedMargins(5, 0, 5, 0).applyTo(projectGroup);
//intermediate composite, which needs to work around the problem with layout of checkbox of BooleanFieldEditor
Composite intermediateComposite = new Composite(projectGroup, SWT.NONE);
BooleanFieldEditor emptyProjectCheckbox = new BooleanFieldEditor("createEmptyProject",
Messages.getString("WizardNewProjectCreationPage.createEmptyProject"), intermediateComposite);
createEmptyProject = emptyProjectCheckbox.getBooleanValue();

Camera position cause objects to disappear

I'm developing an app with blazor client-side and I need to render a 3D scene.
I have an issue and I guess it is material-related.
I have a composition of parallelepipeds where one of them is fully opaque and the others are transparent.
Depending on the camera angle, the transparent ones completely disappear:
Example where everything is visible:
Example with 2 missing:
Example with all missing:
Code for transparent parallelepipeds
var geometry = new THREE.CubeGeometry(item.xDimension * _scene.normalizer, item.yDimension * _scene.normalizer, item.zDimension * _scene.normalizer);
var material = new THREE.MeshBasicMaterial();
var box = new THREE.Mesh(geometry, material);
box.material.color = new THREE.Color("gray");
box.material.opacity = 0.8;
box.material.transparent = true;
Code for the camera:
var camera = new THREE.PerspectiveCamera(60, width / height, 0.1, 100);
camera.position.set(1.3, 1.3, 1.3);
camera.lookAt(0, 0, 0);
I'm using OrbitControls and every object size is between 0 an 1 (_scene.normalizer is for that purpose)
Do you know why this is happening?
Edit:
I found it being a material depth function issue. Do you know which should I use?
Thanks,
Transparency is tricky with WebGL because a transparent object writes to the depthmap, and then the renderer assumes that subsequent objects behind it are occluded so it skips drawing them. You could avoid this by playing with the material's .depthTest and .depthWrite attributes (see the docs):
box.material.color = new THREE.Color("gray");
box.material.opacity = 0.8;
box.material.transparent = true;
box.material.depthWrite = false;

How to draw some figures on a editor with draw2d in a eclipse RCP?

I mean drawing somg simple shape like circle,rectangleFigure,and polylineConnectistrong.It seems that a LightweightSystem has to been constructed on a Canvas such as a Shell.And in a RCP application when I add an extension of an editor,the editor extends org.eclipse.ui.part.EditorPart by default.It has a method called createPartControl.This method has a parameter (Composite parent).
So I write the following code and it give me a Unhandled event loop exception
public void createPartControl(Composite parent) {
Shell shell = parent.getShell();
shell.open();
Display display = shell.getDisplay();
LightweightSystem lws = new LightweightSystem(shell);
IFigure panel = new Figure();
lws.setContents(panel);
RectangleFigure node1 = new RectangleFigure();
RectangleFigure node2 = new RectangleFigure();
node1.setBackgroundColor(ColorConstants.red);
node1.setBounds(new Rectangle(30, 30, 64, 36));
node2.setBackgroundColor(ColorConstants.blue);
node2.setBounds(new Rectangle(100, 100, 64, 36));
PolylineConnection conn = new PolylineConnection();
conn.setSourceAnchor(new ChopboxAnchor(node1));
conn.setTargetAnchor(new ChopboxAnchor(node2));
conn.setTargetDecoration(new PolygonDecoration());
Label label = new Label("Midpoint");
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.buttonLightest);
label.setBorder(new LineBorder());
conn.add(label, new MidpointLocator(conn, 0));
panel.add(node1);
panel.add(node2);
panel.add(conn);
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
}
So how to solve this problem and how to draw these figures on the editor?
As you want to draw inside the editor, you don't need to create new Shell nor dispatch events from the event queue as you would do in a standalone SWT application; just create a Canvas and draw into it. This should help you:
public void createPartControl(Composite parent) {
Canvas canvas = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(canvas);
IFigure panel = new Figure();
lws.setContents(panel);
[...]
panel.add(node1);
panel.add(node2);
panel.add(conn);
}

Using WriteableBitmapEx

I am currently developing metro apps and I need to write text On images.
I found this http://writeablebitmapex.codeplex.com/
But I am new to XAML and dosent know how to use it specifically.
So can anyone say me how do I use it in order to write text on image.
As I have asked this question on MSDN but I have no reply yet.
Edit:
If I use as Muad'Dib I am getting the error as seen in below screenshot:
The Error is: 'Writeable Bitmap Extensions' is ambiguous in the namespace 'System.Windows.Media.Imaging'
there is one possible solution in the Discussions area for WriteableBitmapEx
here is the code from that "article":
public static void DrawText(this WriteableBitmap wBmp,Point at, string text,double fontSize,Color textColor)
{
TextBlock lbl = new TextBlock();
lbl.Text = text;
lbl.FontSize = fontSize;
lbl.Foreground = new SolidColorBrush(textColor);
WriteableBitmap tBmp = new WriteableBitmap(lbl, null);
wBmp.Blit(at, tBmp, new Rect(0, 0, tBmp.PixelWidth, tBmp.PixelHeight), Colors.White, System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Alpha);
}