Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Missing dependency properties (Read 8621 times)
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Missing dependency properties
Nov 11th, 2014 at 11:29am
Print Post  
Hello,

I've noticed that a lot of Diagram's properties are not dependency properties so they can't be bound to VM os set in Wpf styles. I had to overcome this by creating a bunch of wrapper dependency properties for the properties that we modify, like MeasureUnitDP, EnableStyledTextDP, CellFrameStyleDP, TableShapeDP, and so on.

Also, the Diagram's ZoomFactor property is a dependency property but the DiagramView's ZoomFactor is not. As we use the diagram inside a diagram view, we can't use the zooming methods of Diagram's but only of the DiagramView. And still, as we want to bind the ZoomFactor to our VM, we can't use neither zoom method of the DiagramView as they change the non-DP ZoomFactor property. I created a wrapper ZoomFactorDP dependency property bound to the VM, and use custom ZoomIn and ZoomOut DiagramView extension methods.
Anyways, for the DiagramView.ZoomToFit method, as I don't know the inner code, to duplicate it in an extension method, I can't bind the zoom factor to the VM.

Do you have in plan to add more dependency properties? (it's a lot of extra coding adding so many DP wrappers for so many diagram layout/items properties)
How can I use the DiagramView.ZoomToFit() method (or DiagramView.ZoomToRect, basically any method that changes the ZoomFactor property value) and the ZoomFactor new value be reflected via binding to the view model ?

Thanks,
Bogdan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #1 - Nov 12th, 2014 at 5:03pm
Print Post  
Hi,

We actually plan to remove all default-value properties from the Diagram class when we get to next major (v4) release, since they don't play that well with WPF styling. Their values are assigned to properties of newly created items, and changing the diagram's properties later will leave existing items with the old values (hence the need for ClearStyleableProperties method). Now that we've implemented styling system for our components for other platforms, we won't need these Diagram properties even for compatibility reasons.

So better set such global values through styles and themes when possible - in the last few releases we made many properties styleable, such as font, brush and stroke attributes. If you need to set TableNode's Shape and CellFrameStyle specifically, we'll convert them to dependency properties for the 3.2 release.

We see MeasureUnit as something you'd initialize once and not touch anymore, since all other length and size property values would depend on it, but I suppose it won't hurt if we convert it to a dependency property too.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #2 - Nov 17th, 2014 at 11:25am
Print Post  
This build converts MeasureUnit and Table* properties of Diagram class to dependency properties:
https://mindfusion.eu/_beta/wpfdiag.3.2.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Missing dependency properties
Reply #3 - Nov 20th, 2014 at 10:08am
Print Post  
Hi Stoyan,

I've just updated the assemblies, with no other changes, and I got the following exception: "The type initializer for 'MindFusion.Diagramming.Wpf.ArrowHeads' threw an exception." on the Diagram ctor.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #4 - Nov 20th, 2014 at 12:20pm
Print Post  
Hi,

That should be fixed in the latest v3.2 build here:
https://mindfusion.eu/_beta/wpfdiag.3.2.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Missing dependency properties
Reply #5 - Nov 20th, 2014 at 1:44pm
Print Post  
There is still a bug:

Setting these two properties like:

Code
Select All
 <Setter Property="LinkBaseShape" Value="RevWithLine" />
 <Setter Property="LinkHeadShape" Value="DefaultFlow" />
 



Throws "Value cannot be null.\r\nParameter name: property"
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #6 - Nov 21st, 2014 at 8:07am
Print Post  
Where are you setting them from? This works for me:

Code
Select All
<diag:Diagram ....>
<diag:Diagram.Style>
	<Style TargetType="diag:Diagram">
		<Style.Setters>
			<Setter Property="LinkBaseShape" Value="RevWithLine" />
			<Setter Property="LinkHeadShape" Value="DefaultFlow" />
		</Style.Setters>
	</Style>
</diag:Diagram.Style> 

  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Missing dependency properties
Reply #7 - Nov 21st, 2014 at 9:49am
Print Post  
It seems the LinkBaseShape & LinkHeadShape are not DP in the beta release from your last link here.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #8 - Nov 21st, 2014 at 10:59am
Print Post  
It's possible, we converted them in last couple of days. Along with Table* this build should now have the following dependency properties: DefaultShape, Link*Shape, Link*ShapeSize, LinkText, ShapeText:
https://mindfusion.eu/_beta/wpfdiag.3.2.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Missing dependency properties
Reply #9 - Nov 24th, 2014 at 5:20pm
Print Post  
Hi Stoyan,

If I update the assemblies with the ones in your last link, it throws the following exception:

"Object reference not set to an instance of an object" with the StackTrace:

Code (HTML)
Select All
     at MindFusion.Diagramming.Wpf.TableNode.Cell.OnTextAttributeChanged(DependencyPropertyChangedEventArgs e)
   at MindFusion.Diagramming.Wpf.TextPresenter.TextAttributeChanged(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.TreeWalkHelper.InvalidateTreeDependentProperty(TreeChangeInfo info, DependencyObject d, FrameworkObject& fo, DependencyProperty dp, FrameworkPropertyMetadata fMetadata, Style selfStyle, Style selfThemeStyle, ChildRecord& childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent)
   at System.Windows.TreeWalkHelper.InvalidateTreeDependentProperties(TreeChangeInfo info, FrameworkElement fe, FrameworkContentElement fce, Style selfStyle, Style selfThemeStyle, ChildRecord& childRecord, Boolean isChildRecordValid, Boolean hasStyleChanged, Boolean isSelfInheritanceParent)
   at System.Windows.FrameworkElement.InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, Boolean isSelfInheritanceParent)
   at System.Windows.FrameworkElement.OnAncestorChangedInternal(TreeChangeInfo parentTreeState)
   at System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
   at System.Windows.FrameworkElement.OnVisualParentChanged(DependencyObject oldParent)
   at System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
   at System.Windows.Media.Visual.AddVisualChild(Visual child)
   at MindFusion.Diagramming.Wpf.TableNode.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at A.A.J(Visual A)
   at MindFusion.Diagramming.Wpf.Diagram.IR(Visual A)
   at MindFusion.Diagramming.Wpf.Diagram.ER(DiagramItem A)
   at MindFusion.Diagramming.Wpf.Commands.AddItemCmd.Execute(Boolean undoEnabled)
   at MindFusion.Diagramming.Wpf.UndoManager.O(Command A)
   at MindFusion.Diagramming.Wpf.Diagram.AR(DiagramItem A, Boolean B)
   at MindFusion.Diagramming.Wpf.Diagram.AR(DiagramItem A)
   at MindFusion.Diagramming.Wpf.Diagram.OnAddingItem(Object sender, ItemEventArgs e)
   at MindFusion.Diagramming.Wpf.ItemCollectionBase`1.RaiseAdding(UIElement item)
   at MindFusion.Diagramming.Wpf.DiagramNodeCollection.I(UIElement A, Boolean B)
   at MindFusion.Diagramming.Wpf.DiagramNodeCollection.Add(UIElement node)
   at OurCustomDiagram.AddTableNode(DbClassTreeNode treeNode)
   ......
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #10 - Nov 24th, 2014 at 6:40pm
Print Post  
Hi,

That last build also adds support for default cell templates. Is there any Cell style definition without an x:Key in your Xaml? If there is one, could you post its code?

Stoyan
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Missing dependency properties
Reply #11 - Nov 24th, 2014 at 7:24pm
Print Post  
Hi,

We use two cell styles but both having x:Key defined:

Code
Select All
<Style x:Key="CellStyle" TargetType="{x:Type diag:TableNode+Cell}">
        <Setter Property="FontFamily" Value="Tahoma" />
        <Setter Property="FontSize" Value="12" />
        <Setter Property="Template">
            <Setter.Value>
                <DataTemplate DataType="{x:Type diag:TableNode+Cell}">
                    <Border BorderBrush="{StaticResource GrayBrush}" BorderThickness="0,1,1,0">
                        <ContentPresenter Content="{Binding Text}" Margin="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type my:CustomTableNode}}, Path=TextPadding}" VerticalAlignment="Center" />
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="boolCellStyle" TargetType="{x:Type diag:TableNode+Cell}">
        <Setter Property="Template">
            <Setter.Value>
                <DataTemplate DataType="{x:Type diag:TableNode+Cell}">
                    <Border BorderBrush="{StaticResource GrayBrush}" BorderThickness="0,1,0,0">
                        <CheckBox IsChecked="{Binding Tag}" Content="{Binding Text}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #12 - Nov 24th, 2014 at 8:18pm
Print Post  
Hi,

Strange, we can see this call stack happening only when applying default template... If the problem is what we think, this build should fix it:
https://mindfusion.eu/_beta/wpfdiag.3.2.zip

Now I have tables with your styles set both as default and per separate cells working fine in my test app.

If it still doesn't work, please post your table setup code or attach a test project reproducing the exception.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Missing dependency properties
Reply #13 - Nov 24th, 2014 at 8:28pm
Print Post  
Actually we've reproduced that also through WPF's dependency property inheritance. Now that cells have become FrameworkElements, they seem to derive property values from their parent TableNode and Cell.OnTextAttributeChanged callback was called unexpectedly. The build above should fix that situation too.
  
Back to top
 
IP Logged
 
bogdip
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 70
Joined: Sep 8th, 2008
Re: Missing dependency properties
Reply #14 - Nov 25th, 2014 at 12:18pm
Print Post  
Thanks much, now it doesn't crash anymore when adding a table node.

But it raises an exception when I try to delete a node if the diagram's LinkCrossings is set to e.g. Cut. If I set it to Straight, the deletion works fine.

The StackTrace is:
Code (HTML)
Select All
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at MindFusion.Diagramming.Wpf.CollectionBase`1.get_Item(Int32 index)
   at MindFusion.Diagramming.Wpf.Diagram.DU(Boolean A, Int32 B)
--> at MindFusion.Diagramming.Wpf.DiagramLink.ResetCrossings(Rect invalidRect) <--
   at MindFusion.Diagramming.Wpf.DiagramLink.ResetCrossings()
   at MindFusion.Diagramming.Wpf.Diagram.QR(DiagramItem A)
   at MindFusion.Diagramming.Wpf.Commands.RemoveItemCmd.Execute(Boolean undoEnabled)
   at MindFusion.Diagramming.Wpf.UndoManager.O(Command A)
   at MindFusion.Diagramming.Wpf.Diagram.KS(DiagramItem A)
   at MindFusion.Diagramming.Wpf.DiagramNode.ML()
   at MindFusion.Diagramming.Wpf.Diagram.QR(DiagramItem A)
   at MindFusion.Diagramming.Wpf.Commands.RemoveItemCmd.Execute(Boolean undoEnabled)
   at MindFusion.Diagramming.Wpf.UndoManager.O(Command A)
   at MindFusion.Diagramming.Wpf.Diagram.KS(DiagramItem A)
   at MindFusion.Diagramming.Wpf.Diagram.OnRemovingItem(Object sender, ItemEventArgs e)
   at MindFusion.Diagramming.Wpf.ItemCollectionBase`1.RaiseRemoving(DiagramItem item)
   at MindFusion.Diagramming.Wpf.ItemCollectionBase`1.K(T A, Boolean B)
   at MindFusion.Diagramming.Wpf.ItemCollectionBase`1.Remove(T item)
 



It's not thrown on every node deletion from the diagram, but on certain nodes it's thrown.

Please advise,
Thanks
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint