CombinedGeometry/Geometry.Combine() equivalent in Silverlight - wpf

Geometry class in WPF contains a Combine() method which is extremely useful when you need to exclude one geometry from the other, etc. Silverlight version of Geometry doesn't have such a method. The same goes for CombinedGeometry class which does the same.
Are there any other options to exclude one geometry from another in Silverlight?

I'm working on a WPF app which builds user-defined masks using Combine. If there's no answer in SL 4 (none I can see) then my fallback is to send the raw geometry back to the server for combination

I may be very late to answer this question ;-) there is an option called GeometryGroup. You may use this to exclude one geometry from other in Silverlight. You are required to set FillRule="EvenOdd".

Related

Psd slice and creazing new design in atk4

What is the best way to create totally new design for my atk4 application. I have psd files, but i'm not sure if I convert psd to html grid system or some other, what are the best practices?
Also, when i have html, what and how i implement html in atk4, so that atk4 is still upgradable?
thanks, Peter
There are two ways to go:
1) you create your own html/css, based on your psd templates. move that under templates/default/ int o shared.html and in css/img as necessary. add also js_include and other tags that are required to bootup jui interface for atk4
2) alternatively, especially if you plan to use atk4.3, you can setup all your layout using views, boxes and styles that are available out of the box, only adding custom assets and finetuning the color layout using less builder. New css capabilities can be seen here: http://css.agiletoolkit.org
Normally, we stick to (2) for intranet solutions or where minor design tweaks are required. If your layout is very custom, go with (1), as it gives you full freedom.

WPF Binding to Proxy

I have a number of collection classes that implement their own custom update notification. It should be pretty easy to translate these notifications to an INotifyCollectionChanged implementation in a proxy class.
INotifyPropertyChanged is already taken care of; this question is just about collection proxies.
So, what I'm looking for is a way of creating the proxies that is relatively easy to use from XAML. This is particularly true for sub-collections. The custom collection classes are part of a library that cannot be modified (nor derived from). It's also not possible to replace the collection types with INotifyCollectionChanged-compatible equivalents, because the data-updating code is outside my control.
I'd prefer a solution that works with SL as well, but it's not a strict requirement.
So far, I believe the following approaches are viable:
Define a TypeDescriptionProvider registered for the collection classes that adds a Proxy property. This allows Binding paths to dot-into the proxy. It seems that this solution is easiest from a XAML perspective, but is not SL-compatible.
Define a value converter that creates the proxies. This would work with a bit more work from the XAML side. It should work for SL. However, it may require "intermediate" visual elements to hold the value converter result if more than one value conversion is necessary on a path.
I looked into ObjectDataProvider, but I don't think it can be used in this situation (the proxy creation method must be generic on the type of objects in the container).
Any recommendations on which of these two approaches is better, or any other approaches?
Paul Stovell created an editable collection adapter which in and of itself probably won't satisfy your needs, but it should give you a good starting point to create an appropriate adapter/proxy.
http://www.paulstovell.com/editable-collection-adapter
I've decided to move forward with a type converter that is also a MarkupExtension, as described by this blog post.
MarkupExtension isn't currently supported by Silverlight, but it will be in v5.

Change filter in Silverlight Pivot Viewer to use AND instead of OR

I need to modify the way the filter acts in the Silverlight Pivot viewer.
I have this filter:
Keywords:
x Keyword a
_ Keyword b
x Keyword c
_ Keyword d
_ Keyword e
The filter generates “Keyword a OR Keyword c”. What I need is “Keyword a AND Keyword c”.
Is that possible?
Any help is appreciated!
What Poker Villain says is quite right but that doesn't mean the PivotViewer is not a solution for you. I had a similar problem with a system I've been working on and managed to find a suitable way of making the PivotViewer play nice. This will only work for JIT collections though since it relies on re-fetching the data.
Essentially the system I've been working on is a case management system. Much of the data associated with a case is mutually exclusive and so fits the model of the PivotViewer but there is also the ability to add 'tags' to a case and like you suggest, often the user will want to combinational logic there. Here's what I did to fix the problem.
First off,..you're gonna want a copy of Silverlight Spy. Now in the explorer tab of SSpy, you can drill right down the Visual Tree and look at the guts of the PivotViewer. Here's how mine looks...
You can see I've drilled right down into the control named 'PART_FacetPane'. Below that there's a bunch of CustomAccordianItems. Essentially, you just need to subclass the PivotViewer (that's why mine says PivotViewerEx) and override the OnApplyTemplate method.
In here you will be able to use GetTemplateChild or some other means to navigate the VisualTree and add another control yourself. In my project, I used a simple tag cloud control I'd previously built.
What I do is handle the events of the tag cloud control and append querystring values to the URL used to build the CXML and filter the data based on these parameters. It's not as fluid as being able to filter the data 'live' as it were but it's a solution for now.
It's probably worth mentioning that depending on your circumstances, you may need to add a final, randomly generated querystring value to the CXML URL so you don't get a cached copy of the data.
HTH, Stimul8d.
bottom line ... NO.
You get what you get with this control. (for now)
but you could generate a "dummy" facet that was the concatenation of all the keywords for an item. But if you had more than a few keywords, it would look very ugly.

WPF - Is there something similar to PathCompactPath?

I would like to compact filepaths the same way that PathCompactPath does in Windows Forms, so when you stretch out the parent control, more of the filepath becomes visible and vice versa.
Since PathCompactPath uses character sizes, is there any similar in WPF that uses pixel sizes/dpi? Or a converter of some kind?
First of all, IMHO PathCompactPath does not exist in Windows Forms. You would have to use PInvoke there.
Unfortunately this functionality is also not in WPF. The closest to what you need is TextBlock.TextTrimming. I also do not know of any 3rd party control that can do this. You yould however roll your own. Using FormattedText (.Width and .Height) you can measure your string before you render it. You can also use it to actually render text.

Performance of DrawingVisual vs Canvas.OnRender for lots of constantly changing shapes

I'm working on a game-like app which has up to a thousand shapes (ellipses and lines) that constantly change at 60fps. Having read an excellent article on rendering many moving shapes, I implemented this using a custom Canvas descendant that overrides OnRender to do the drawing via a DrawingContext. The performance is quite reasonable, although the CPU usage stays high.
However, the article suggests that the most efficient approach for constantly moving shapes is to use lots of DrawingVisual instances instead of OnRender. Unfortunately though it doesn't explain why that should be faster for this scenario.
Changing the implementation in this way is not a small effort, so I'd like to understand the reasons and whether they are applicable to me before deciding to make the switch. Why could the DrawingVisual approach result in lower CPU usage than the OnRender approach in this scenario?
From Pro WPF in C# 2008:
The problem posed by these
applications isn't the complexity of
the art, but the sheer number of
individual graphic elements. Even if
you replace your Path elements with
lighter weight Geometry objects, the
overhead will still hamper the
application's performance. The WPF
solution for this sort of situation is
to use the lower-level visual layer
model. The basic idea is that you
define each graphical element as a
Visual object, which is an extremely
lightweight ingredient that has less
overhead than a Geometry object or a
Path object.
What it boils down to is that every single one of those ellipses and lines you're creating is a separate FrameworkElement; that means it supports not only hit testing, but also layout, input, focus, events, styles, data-binding, resources, and animation. That's a pretty heavy-weight object for what you're trying to do! The Visual object skips all of that and inherits directly from DependencyObject. It still provides support for hit-testing, coordinate transformation, and bounding-box calculations, but none of the other stuff that the shapes support. It's far more lightweight and would probably improve your performance immensely.
EDIT:
Ok, I misread your question the first time around.
In the case that you are using OnRender, it really depends how you are creating the visuals and displaying them. If you are using a DrawingContext and adding all of the visuals to a single element, this is no different than using the DrawingVisual approach. If you were creating a separate element for each Visual created, then this would be a problem. It seems to me that you are doing things the right way.
Everyone in the answers got it wrong. The question is whether rendering shapes directly in the drawing context is faster than creating DrawingVisual. The answer is obviously 'yes'. Functions such as DrawLine, DrawEllipse, DrawRectangle etc. do not create any UI Element. DrawingVisual is much slower because it does create a UI Element, although a lightweight one. The confusion in the answers is because people simply copy/paste the DrawingVisual performs better than distinct UIElement shapes statement from MSDN.
I thought Petzold explains in this paragraph;
The ScatterPlotVisual class works by
creating a DrawingVisual object for
each DataPoint. When the properties of
a DataPoint object change, the class
only needs to alter the DrawingVisual
associated with that DataPoint.
Which builds on an earlier explanation;
Whenever the ItemsSource property
changes, or the collection changes, or
a property of the DataPoint objects in
the collection changes,
ScatterPlotRender calls
InvalidateVisual. This generates a
call to OnRender, which draws the
entire scatter plot.
Is this what your asking about?
By the way, this is a fairly recent high-performance WPF tutorial, many tens of thousands of points in that plot, it is 3D rendered and animated also (even uses mouse input to drive some of the transforms).
In my tests however (panning animations), I notice no difference in speed. I would say that using a host element for many drawing visuals is a bit faster. This approach where you build your visual tree with many visuals gives you more control. Moreover, when you want to do a complex hit testing, the filtering process is faster because you can skip entire "branches" of visuals

Resources