Posts Tagged ‘WPF’

First Pull-request created.

Well, it had to happen some day.

I’ve found an issue in a project we are using @ work. I’ve created a fix and I want to share it!.

So this project is hosted on github, and it is indeed simple to add fixes.

Just follow these steps :

  1. Fork the project
  2. Create a feature / fix branch
  3. Apply fix.
  4. Push to github.
  5. View this branch on github
  6. Push the “Create Pull Request” button

It will then show you if it can be merged at all. Add some information and you are done!

better details

The fix.

I’ve created a rather simple fix. We are using the “Fluent.Ribbon” for a modern look and feel. But some of our controls are still winforms. There is nothing wrong with winforms, but a mixture of wpf and winforms is not always ideal.

Anyway, we have a combobox in our ribbon and when a winforms control has focus and you try to open this combobox in your ribbon, it acts up.  repro : 


We have found this message in the debug window:

System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=IsDropDownOpen; DataItem=’ComboBox’ (Name=’StyleCbx’); target element is ‘ToggleButton’ (Name=’ToggleButton’); target property is ‘IsChecked’ (type ‘Nullable`1′) NullReferenceException:’System.NullReferenceException: Object reference not set to an instance of an object.
at Fluent.ComboBox.OnDropDownOpened(EventArgs e)
at System.Windows.Controls.ComboBox.OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at MS.Internal.Data.PropertyPathWorker.SetValue(Object item, Object value)
at MS.Internal.Data.ClrBindingWorker.UpdateValue(Object value)
at System.Windows.Data.BindingExpression.UpdateSource(Object value)’

Turns out that the fix was rather simple. The combobox of fluent expected the Keyboard.FocusedElement, to always be non-null.

Well this is not the case when dealing with a mixed technology window. So the fix was created and a pull request has been offered.



DrawCurve / AddCurve for WPF / Cardinal Spline

For my project I need to draw Cardinal splines. Preferable the same way I was used to with the System.Drawing.Graphics or System.Drawing.Drawing2D.GraphicsPath. Not knowing much about splines, I noticed the number of PathPoints on a graphics path. The curve is drawn with beziers, so it’s some sort of string of beziers that make up this cardinal spline.

This project results in the same curves as you are used to with the graphics object (but this works with doubles not with floats). Tension and open and closed params are supported!

Anyway long story short, this project calculates control points for beziers. The curve will be draw with beziers, thus the outcome is exactly the same as with the Graphics object. I’ve seen other examples drawing the curve by them self calculating 100’s of points on the bezier it self .

Yes the graphics object does the same thing see msdn (quote:”Remarks The user must keep the original points if they are needed. The original points are converted to cubic Bézier control points internally, therefore there is no mechanism for returning the original points.”) .

If you draw a curve with 3 points, 7 points are needed to draw the curve, thus a performance gain(? not measured!) without losing the nice smoothness of the curve.

here is a screen shot:


and here is the code

comments are welcome, Can u use this, or are you missing something?