Skip to content

Commit

Permalink
Fixed null exception XamlExporter (helix-toolkit#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauNguyenVan committed Aug 8, 2023
1 parent 660c85f commit ece1821
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ private void FileExport()

private void CopyXaml()
{
if (this.CurrentModel is null)
return;
var rd = XamlExporter.WrapInResourceDictionary(this.CurrentModel);
Clipboard.SetText(XamlHelper.GetXaml(rd));
}
Expand All @@ -175,7 +177,7 @@ private async Task<Model3DGroup> LoadAsync(string model3DPath, bool freeze)
return await Task.Factory.StartNew(() =>
{
var mi = new ModelImporter();
if (freeze)
{
// Alt 1. - freeze the model
Expand Down
4 changes: 2 additions & 2 deletions Source/HelixToolkit.Wpf.Shared/Exporters/XamlExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public static ResourceDictionary WrapInResourceDictionary(object obj)
i++;
}
}
else
else if(obj != null)
{
rd.Add("Model", obj);
}

return rd;
}

Expand Down
5 changes: 1 addition & 4 deletions Source/HelixToolkit.Wpf.Shared/Helpers/XamlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public static string GetXaml(Viewport3D view)
XamlWriter.Save(view, xw);

string xaml = sb.ToString();
xaml =
xaml.Replace(
string.Format("<Viewport3D Height=\"{0}\" Width=\"{1}\" ", view.ActualHeight, view.ActualWidth),
"<Viewport3D ");
xaml = xaml.Replace(string.Format("<Viewport3D Height=\"{0}\" Width=\"{1}\" ", view.ActualHeight, view.ActualWidth), "<Viewport3D ");

return xaml;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,6 @@ public class ViewCubeVisual3D : ModelVisual3D
public static readonly DependencyProperty ViewportProperty = DependencyProperty.Register(
"Viewport", typeof(Viewport3D), typeof(ViewCubeVisual3D), new PropertyMetadata(null));

/// <summary>
/// Set or Get if view cube edge clickable.
/// </summary>
public bool EnableEdgeClicks
{
get { return (bool)GetValue(EnableEdgeClicksProperty); }
set { SetValue(EnableEdgeClicksProperty, value); }
}

/// <summary>
/// Identifies the <see cref="EnableEdgeClicks"/> dependency property.
/// </summary>
Expand Down Expand Up @@ -345,9 +336,18 @@ public Viewport3D Viewport
this.SetValue(ViewportProperty, value);
}
}

/// <summary>
/// Set or Get if view cube edge clickable.
/// </summary>
public bool EnableEdgeClicks
{
get { return (bool)GetValue(EnableEdgeClicksProperty); }
set { SetValue(EnableEdgeClicksProperty, value); }
}
private double Overhang => 0.001 * Size;
#endregion Properties

#region Fields
/// <summary>
/// The dictionary [object,(normal vector,up vector)].
/// </summary>
Expand All @@ -368,7 +368,7 @@ public Viewport3D Viewport
private Vector3D _frontVector;
private Vector3D _leftVector;
private Vector3D _upVector;

#endregion Fields
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref = "ViewCubeVisual3D" /> class.
Expand Down

0 comments on commit ece1821

Please sign in to comment.