protected async Task<IRandomAccessStream> GenerateImage(UIElement diagram) { // Render to an image at the current system scale and retrieve pixel contents var renderTargetBitmap = new RenderTargetBitmap(); // unselect all nodes ObservableCollection<TraNode> nodes = ((diagram as SfDiagram).Nodes as ObservableCollection<TraNode>); if(nodes != null && nodes.Count > 0) { foreach (var node in nodes) { node.IsSelected = false; } } await renderTargetBitmap.RenderAsync(diagram); var pixelBuffer = await renderTargetBitmap.GetPixelsAsync(); var pixelBytes = new byte[pixelBuffer.Length]; using (var reader = DataReader.FromBuffer(pixelBuffer)) { reader.ReadBytes(pixelBytes); } IRandomAccessStream stream = new InMemoryRandomAccessStream(); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream); encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, pixelBytes); await encoder.FlushAsync(); return stream; } |
<DataTemplate x:Key="nodeImageTemplate"> <Border Background="White"> <Image Source="{Binding Path=CustomImage}" Stretch="Fill" /> </Border> </DataTemplate> <syncfusion:SfDiagram.Nodes> <syncfusion:NodeCollection> <syncfusion:NodeViewModel ContentTemplate="{StaticResource nodeImageTemplate}" Pivot="0,0" /> </syncfusion:NodeCollection> </syncfusion:SfDiagram.Nodes> |
<syncfusion:SfDiagram.Background> <ImageBrush ImageSource="/Assets/BackgroundImage.jpg" Stretch="Uniform" AlignmentX="Left" AlignmentY="Top" /> </syncfusion:SfDiagram.Background> |
<!--#Add the Below code into the Page.Resources--> <!--#Image Brush --> <ImageBrush x:Key="bgimage" ImageSource="/Assets/BackgroundImage.jpg" Stretch="Fill"/> <!--# PageSettings --> <syncfusion:PageSettings x:Key="diagrampage" PageWidth="1000" PageHeight="1000" PageBorderBrush="Red"PageBackground="{StaticResource bgimage}" /> <!--# Initializes Diagram and Bind the PageSettings properties--> <syncfusion:SfDiagram x:Name="diagram" PageSettings="{StaticResource diagrampage}"> |
"And also, please adjust the PageWidth and PageHeight as per the requirement. " |
<!--#region set the image as Diagram Background--> <syncfusion:SfDiagram.Background> <ImageBrush ImageSource="/Assets/BackgroundImage.jpg" Stretch="Fill" AlignmentX="Left" AlignmentY="Top" /> </syncfusion:SfDiagram.Background> //InitializeDiagram Method. private void InitializeDiagram() { diagram.ScrollSettings.ScrollLimit = ScrollLimit.Diagram; diagram.PageSettings.PageBorderBrush = new SolidColorBrush(Windows.UI.Colors.Transparent); diagram.PageSettings.PageBackground = new SolidColorBrush(Windows.UI.Colors.Transparent); } |
<!--#Add the Below code into the Page.Resources--> <ImageBrush x:Key="bgimage" ImageSource="/Assets/BackgroundImage.jpg" Stretch="Fill"/> <syncfusion:PageSettings x:Key="diagrampage" PageWidth="1120" PageHeight="680" PageBorderBrush="Red" PageBackground="{StaticResource bgimage}" /> <!--#region Initializes Diagram--> <syncfusion:SfDiagram x:Name="diagram" PageSettings="{StaticResource diagrampage}"> //InitializeDiagram Method. private void InitializeDiagram() { diagram.ScrollSettings.ScrollLimit = ScrollLimit.Diagram; } |
private void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args) { if (args.ItemSource == ItemSource.Stencil) { var dropedItem = args.Item as NodeViewModel; if (dropedItem != null) { Thickness = DefaultThickness; if (dropedItem.Key.ToString().ToLower().Contains("arrow")) { Fill = DefaultFill; Stroke = DefaultStroke; dropedItem.ShapeStyle = GetDefaultStyle(); } else { Fill = DefaultFill; Stroke = null; dropedItem.ShapeStyle = GetDefaultStyle(); } } } } |
private void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args) { if (args.ItemSource == ItemSource.Stencil) { var dropedItem = args.Item as NodeViewModel; } if (diagram.Nodes != null) { foreach (NodeViewModel node in diagram.Nodes as DiagramCollection<NodeViewModel>) { if (node.Key != null) { if (thick != 0) Thickness = DefaultThickness; if (node.Key.ToString().ToLower().Contains("arrow")) { Fill = DefaultFill; Stroke = DefaultStroke; node.ShapeStyle = GetDefaultStyle(); } else { Stroke = DefaultStroke; Fill = null; node.ShapeStyle = GetDefaultStyle(); } } } } } |
private Style GetDefaultStyle() { Style s = new Style(); s.TargetType = typeof(Windows.UI.Xaml.Shapes.Path); if (Fill != null) { s.Setters.Add(new Setter(Windows.UI.Xaml.Shapes.Path.FillProperty, DefaultFill)); } if (!double.IsNaN(Thickness) && !double.IsInfinity(Thickness)) { s.Setters.Add(new Setter(Windows.UI.Xaml.Shapes.Path.StrokeThicknessProperty, DefaultThickness)); } if (Stroke != null) { s.Setters.Add(new Setter(Windows.UI.Xaml.Shapes.Path.StrokeProperty, DefaultStroke)); } s.Setters.Add(new Setter(Windows.UI.Xaml.Shapes.Path.StretchProperty, Stretch.Fill)); return s; } |
//DragEnterEvent (diagram.Info as IGraphInfo).DragEnter += MainPage_DragEnter; private void MainPage_DragEnter(object sender, ItemDropEventArgs args) { if (args.ItemSource == Cause.Stencil) { var dropedItem = args.Source as Node; if (dropedItem != null) { dropedItem.ShapeStyle = GetCustomStyle(); } } } Here, diagram is instance of SfDiagram. |
06.30.16.372063 : FirstPage - Button_Click() - start 06.30.16.379065 : MainPage - MainPage() - start 06.30.16.724063 : MainPage - InitializeDiagram() - start 06.30.16.727065 : MainPage - InitializeDiagram() - end 06.30.16.742063 : MainPage - MainPage() - end 06.30.16.748567 : FirstPage - Button_Click() - end |
07.00.09.540502 : FirstPage - Button_Click() - start 07.00.09.556127 : MainPage - MainPage() - start 07.00.10.540569 : MainPage - InitializeDiagram() - start 07.00.10.556196 : MainPage - InitializeDiagram() - end 07.00.10.603076 : MainPage - MainPage() - end 07.00.10.618700 : FirstPage - Button_Click() - end |
<syncfusion:SfDiagram.Background> <ImageBrush x:Name="photo" ImageSource="/Assets/image.jpeg" Stretch="Uniform" AlignmentX="Left" AlignmentY="Top" /> </syncfusion:SfDiagram.Background> |
protected async Task<IRandomAccessStream> GenerateImage(UIElement diagram) { var renderTargetBitmap = new RenderTargetBitmap(); DiagramCollection<NodeViewModel> nodes = (diagram as SfDiagram).Nodes as DiagramCollection<NodeViewModel>; if (nodes != null && nodes.Count > 0) { foreach (var node in nodes) { node.IsSelected = false; } } await renderTargetBitmap.RenderAsync(diagram); var pixelBuffer = await renderTargetBitmap.GetPixelsAsync(); var pixelBytes = new byte[pixelBuffer.Length]; using (var reader = DataReader.FromBuffer(pixelBuffer)) { reader.ReadBytes(pixelBytes); } IRandomAccessStream stream = new InMemoryRandomAccessStream(); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegXREncoderId, stream); encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, pixelBytes); await encoder.FlushAsync(); return stream; } |
protected async Task<IRandomAccessStream> GenerateImage() { var renderTargetBitmap = new RenderTargetBitmap(); DiagramCollection<NodeViewModel> nodes = (diagram as SfDiagram).Nodes as DiagramCollection<NodeViewModel>; if (nodes != null && nodes.Count > 0) { foreach (var node in nodes) { node.IsSelected = false; } } // debug int newDiagWidth = 0; int newDiagHeight = 0; var imgWidth = (double)((BitmapSource)((ImageBrush)(diagram).Background).ImageSource).PixelWidth; var imgHeight = (double)((BitmapSource)((ImageBrush)(diagram).Background).ImageSource).PixelHeight; var widthRatio = imgWidth / this.diagram.ActualWidth; var heightRatio = imgHeight / this.diagram.ActualHeight; if (widthRatio > heightRatio) { newDiagWidth = (int)this.diagram.ActualWidth; newDiagHeight = (int)((this.diagram.ActualWidth / imgWidth) * imgHeight); } else { newDiagWidth = (int)((this.diagram.ActualHeight / imgHeight) * imgWidth); newDiagHeight = (int)(this.diagram.ActualHeight); } diagram.Width = newDiagWidth; diagram.Height = newDiagHeight; diagram.ScrollViewerRenderMode = ScrollViewerRenderMode.Hidden; // end debug await renderTargetBitmap.RenderAsync(diagram); var pixelBuffer = await renderTargetBitmap.GetPixelsAsync(); var pixelBytes = new byte[pixelBuffer.Length]; using (var reader = DataReader.FromBuffer(pixelBuffer)) { reader.ReadBytes(pixelBytes); } IRandomAccessStream stream = new InMemoryRandomAccessStream(); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegXREncoderId, stream); encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, pixelBytes); await encoder.FlushAsync(); return stream; } |
S.no |
Query |
Response | ||
1 |
is there a way to hide them? In the WPF doc (WPF - Diagram View), there are references to "HorizontalScrollbarVisibility" and "VerticalalScrollbarVisibility", but I didn't found how to use them on UWP... |
Requirement: Need to hide the ScrollBar(horizontal/Vertical).
To achieve your requirement, please follow the below suggestion.
Suggestion 1:
In the sample, please set the scrolllimit which is in the ScrollSettings as Diagram. It helps to achieve your requirement. We have provided a code example to represent this. Please refer the code example as below.
Code example:
Suggestion 2:
In the sample, please set the ScrollViewerRenderMode of the Diagram as Hidden. It helps to achieve your requirement. We have provided a code example to represent this. Please refer the code example as below
Note:
If the provided information not meet your requirement. Please provide sample to achieve your requirement at the earliest. | ||
2 |
Is it possible to optimize the opening of the page? |
Currently, we are checking the optimize way of opening the diagram in Tablet. We will get back to you once we found the solution. |
Hi Pierre,Requirement:” Need to set Selected Color directly to the Dragging Nodes from Stencil”We have analyzed and provided a solution to achieve your requirement. Please use DragEnter Event instead of using ItemAdded Event. We have provided a code example and Video to represent your requirement. Please refer the code example and video link as below.Code Example:
//DragEnterEvent(diagram.Info as IGraphInfo).DragEnter += MainPage_DragEnter;private void MainPage_DragEnter(object sender, ItemDropEventArgs args){if (args.ItemSource == Cause.Stencil){var dropedItem = args.Source as Node;if (dropedItem != null){dropedItem.ShapeStyle = GetCustomStyle();}}}Here, diagram is instance of SfDiagram.Regards,Keerthivasan R.