Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) [BETA] Saving Crash and UserControl Clipping (Read 16555 times)
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
[BETA] Saving Crash and UserControl Clipping
Sep 10th, 2008 at 11:24pm
Print Post  
I've switched to using the WpfDiagram 2.0.0 beta, and everything is going well, except for two bugs.

First, saving the diagram as Xaml produces an exception. We're calling diagram.SaveToXml(), and getting an "Ambiguous match found." exception, with the following stack trace:
Code
Select All
   at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
   at System.Type.GetProperty(String name)
   at MS.Internal.ComponentModel.DependencyPropertyKind.get_IsDirect()
   at MS.Internal.ComponentModel.DependencyPropertyKind.get_IsAttached()
   at MS.Internal.ComponentModel.APCustomTypeDescriptor.GetProperties(Attribute[] attributes)
   at MS.Internal.ComponentModel.APCustomTypeDescriptor.GetProperties()
   at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultExtendedTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
   at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes)
   at System.ComponentModel.TypeDescriptor.GetProperties(Object component)
   at System.Windows.Markup.Primitives.ElementMarkupObject.<GetProperties>d__0.MoveNext()
   at System.Windows.Markup.Primitives.MarkupWriter.RecordNamespaces(Scope scope, MarkupObject item, IValueSerializerContext context, Boolean lastWasString)
   at System.Windows.Markup.Primitives.MarkupWriter.WriteItem(MarkupObject item)
   at System.Windows.Markup.Primitives.MarkupWriter.SaveAsXml(XmlWriter writer, MarkupObject item)
   at System.Windows.Markup.Primitives.MarkupWriter.SaveAsXml(XmlWriter writer, Object instance)
   at System.Windows.Markup.XamlWriter.Save(Object obj, Stream stream)
   at MindFusion.Diagramming.Wpf.XmlPersistContext.WriteXaml(Object elt, String name, XmlElement parent)
   at MindFusion.Diagramming.Wpf.DiagramNodeAdapter.SaveToXml(XmlElement xmlElement, XmlPersistContext context)
   at MindFusion.Diagramming.Wpf.XmlPersistContext.xcfee0917c3bf82cc(DiagramItem xccb63ca5f63dc470, XmlElement x1ea18269223b2a9c, String x121383aa64985888)
   at MindFusion.Diagramming.Wpf.Diagram.SaveToXml(XmlDocument document) 



The contents of the diagram we're trying to save is multiple DiagramNodeAdapters, each containing a usercontrol (all the same class of usercontrol), with various properties, and links between those nodes.


Second, as of the beta, it now correctly detects the edges of usercontrols in DiagramNodeAdapters, for where to connect links. However, those clipping edges don't update when the size of the node changes (or the links don't update to hit the new clipping edges), until the next time the node is moved. For example, our nodes are sized based on some data about them. However, that's an option that the user can toggle. When it's off, all nodes are the same size (except the root node which is slgihtly larger). When it's on, nodes are sized based on a value in their custom data. When this is toggled, the nodes resize, but the links hook up wrong. Screenshots below:





Any help would be greatly appreciated. Thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: [BETA] Saving Crash and UserControl Clipping
Reply #1 - Sep 11th, 2008 at 8:30am
Print Post  
Hi,

Select the "when thrown" option for CLR exceptions in the Debug/Exceptions window. Now what is the value of the 'name' parameter when GetPropertyImpl throws that exception?

Are you resizing the nodes by setting DiagramNodeAdapter.Bounds, or by changing properties of the hosted controls? I suppose it's the latter; in such case, enable the DiagramNodeAdapter.AutoUpdateSize property. It specifies whether the nodes' Bounds value should update automatically to match the size of the hosted controls.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
Re: [BETA] Saving Crash and UserControl Clipping
Reply #2 - Sep 11th, 2008 at 5:38pm
Print Post  
Stoyo wrote on Sep 11th, 2008 at 8:30am:
Hi,

Select the "when thrown" option for CLR exceptions in the Debug/Exceptions window. Now what is the value of the 'name' parameter when GetPropertyImpl throws that exception?

Using "when thrown", and switching to using WpfDiagram source code instead of prebuilt DLL, and loading the WPF public symbols, I was able to find what was making it unable to save (a certain property on our usercontrol), and work around it. Thanks!

Stoyo wrote on Sep 11th, 2008 at 8:30am:
Are you resizing the nodes by setting DiagramNodeAdapter.Bounds, or by changing properties of the hosted controls? I suppose it's the latter; in such case, enable the DiagramNodeAdapter.AutoUpdateSize property. It specifies whether the nodes' Bounds value should update automatically to match the size of the hosted controls.

Currently, I'm setting both the Bounds of the DiagramNodeAdapter and the Height/Width of the UserControl, along with setting DiagramNodeAdapter.AutoUpdateSize to true. Besides the issue in my original post, this also makes it so resizing the node doesn't resize the usercontrol; the usercontrol is just centered in the resized node, staying the same size.

Ideally, I'd like the node to control the size of the UserControl, so that if the user wants to, they can resize it. In order to do that, it would make sense to me to set the Bounds of the DiagramNodeAdapter, leave AutoUpdateSize false, and set the UserControl to no Height/Width, and vertical/horizontal align of Stretch.

However, that doesn't work as expected. It works, except the content of the usercontrol doesn't get restricted to the size of the DiagramNodeAdapter. There's text in the UserControl, that's set to wrap (see "Sample Text" above). Unfortunately, it thinks it's got unlimited space to lay itself out, so doesn't wrap. For example, if the DiagramNodeAdapter is set to be 100x100, and the usercontrol contains text that's 150 wide, instead of the usercontrol being 100x100 with two lines of text, it ends up being 150x100 (clipped to just the leftmost 100x100), with one line of text. If I explicitly set its Width/Height, it wraps as expected. (EDIT: I've also tried this with AutoUpdateSize set to true; no change. I'm trying to get the size to update the other way from what AutoUpdateSize is intended to do, I think)

I'm guessing the DiagramNodeAdapter needs to tell the usercontrol its width/height as AvailableArea in its measure/layout calls? Or is there another way to do this that I'm missing?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: [BETA] Saving Crash and UserControl Clipping
Reply #3 - Sep 12th, 2008 at 8:19am
Print Post  
A difference between versions 1 an 2 is that now if the hosted control specifies its own FrameworkElement.Widht and Height properties, the DiagramNodeAdapter will always Arrange() the control with the specified size. If you have Width and Height set in the usercontrol's XAML, remove them, and the control should be arranged in the space specified through node.Bounds.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
Re: [BETA] Saving Crash and UserControl Clipping
Reply #4 - Sep 15th, 2008 at 5:38pm
Print Post  
That doesn't seem to match what I'm seeing.


That's a DiagramNodeAdapter, which I explicitly set the Bounds on, in code. The UIElement it contains is a usercontrol, with no Width/Height/Bounds set at all, and VerticalAlignment/HorizontalAlignment set to Stretch. DiagramNodeAdapter.AutoUpdateSize is false; when set to true, the whole node is reduced to the smallest size that will fit the usercontrol's text, as expected, and not desired.

The closest to desired functionality that I've gotten has been to make my usercontrol's first level child (a Border object) have Width and Height be bindings to the usercontrol's ActualWidth and ActualHeight. That produced the desired functionality, except that it only makes the usercontrol bigger as the node gets bigger, the usercontrol stays big when the node is made small again, and is clipped.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: [BETA] Saving Crash and UserControl Clipping
Reply #5 - Sep 16th, 2008 at 7:01am
Print Post  
Could you copy the usercontrol's xaml code here?
  
Back to top
 
IP Logged
 
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
Re: [BETA] Saving Crash and UserControl Clipping
Reply #6 - Sep 16th, 2008 at 5:07pm
Print Post  
Sure:

Code
Select All
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CS.DataPlace.VentureAnalytics"
x:Class="CS.DataPlace.VentureAnalytics.DiagramNodes.AreaNode"
FontFamily="Segoe UI" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border x:Name="borderMain" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="2" CornerRadius="32767">
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="2">
<TextBlock x:Name="textBlockName" HorizontalAlignment="Stretch" TextWrapping="Wrap" TextAlignment="Center" LineStackingStrategy="BlockLineHeight"/>
<TextBlock x:Name="textBlockMiddle" HorizontalAlignment="Stretch" TextWrapping="Wrap" TextAlignment="Center"/>
<DockPanel x:Name="dockPanelBottom" LastChildFill="True">
<StackPanel x:Name="spacerLeft" DockPanel.Dock="Left"/>
<StackPanel x:Name="spacerRight" DockPanel.Dock="Right"/>
<TextBlock x:Name="textBlockBottom" HorizontalAlignment="Stretch" TextWrapping="Wrap" TextAlignment="Center"/>
</DockPanel>
</StackPanel>
</Border>
</UserControl> 



I'm adding some bindings to some of those controls at runtime, but only for things like Text and FontSize. Let me know if any more details would help.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: [BETA] Saving Crash and UserControl Clipping
Reply #7 - Sep 17th, 2008 at 12:03pm
Print Post  
This happens because the TextBlocks cannot become smaller than the size of their text. When node.Bounds becomes smaller than the text size, that prevents the stackpanel and border from fitting in there and the nodes are clipped. You might look for some TextBlock property that would clip the text when enabled, instead of limiting the textblock size.

Stoyan
  
Back to top
 
IP Logged
 
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
Re: [BETA] Saving Crash and UserControl Clipping
Reply #8 - Sep 17th, 2008 at 8:40pm
Print Post  
I've been investigating this extensively, and found that there seems to be two separate problems.

First, TextBlocks seem to not wrap, even when wrapping is set, unless their parent's width is set smaller than the length of the full line, even after Measure and Arrange are called on them with widths that should make them wrap. I've gotten around this by overriding ArrangeOverride in my usercontrol, and setting the MaxWidth of the textblocks to the arrangeBounds (minus some padding).

Second, the DiagramNodeAdapter is calling Arrange on the UIElement child, passing it the available size. However, ArrangeOverride on the UIElement, and all Arrange calls to children of it, don't get the passed available size, because the previously measured size is larger; they get that larger measured size instead. To solve this, I added a Measure call before Arrange is called, by DiagramNodeAdapter.

(line numbers/code based on 2.0.0 beta source, I haven't upgraded to 2.0.0 release yet)
Just before DiagramNodeAdapter.cs#124:
Code
Select All
item.Arrange(new Rect(Utilities.NaNToNum(Size, item.DesiredSize))); 


Added a Measure call with the same size:
Code
Select All
item.Measure(Utilities.NaNToNum(Size, item.DesiredSize)); 




With both of these changes in place, I'm finally seeing the desired behavior.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: [BETA] Saving Crash and UserControl Clipping
Reply #9 - Sep 18th, 2008 at 7:33am
Print Post  
I'm not sure about that. The result returned from Utilities.NaNToNum is its first argument, which is the size of DiagramNode.Bounds. Calling Measure before Arrange should matter only if you cache some results calculated during the measure phase and use them in the arrange phase.
  
Back to top
 
IP Logged
 
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
Re: [BETA] Saving Crash and UserControl Clipping
Reply #10 - Sep 18th, 2008 at 5:21pm
Print Post  
Right, the NaNToNum call is just to use the item's desiredsize as a fallback, which should never happen.

Calling Measure first allows the controls to cache the results of their previous measure phase for use in the next arrange (controls already do this, built-in).
  
Back to top
 
IP Logged
 
chadd.nervig
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Aug 12th, 2008
Re: [BETA] Saving Crash and UserControl Clipping
Reply #11 - Sep 29th, 2008 at 3:22pm
Print Post  
Hey, any update on a built-in solution to this issue?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: [BETA] Saving Crash and UserControl Clipping
Reply #12 - Sep 30th, 2008 at 8:23am
Print Post  
We'll probably add a built-in Measure call. Though our developers are not convinced it's correct for your control to cache whatever layout information when in the Measure phase, since parent controls are not required to call Arrange with the same size as the one passed to Measure.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint