Skip to content

Commit

Permalink
Merge pull request #75 from SyncfusionExamples/WPF-904210-ToChangethe…
Browse files Browse the repository at this point in the history
…)propertygrid_sample

WPF-904210 - To update the PropertyGrid sample
  • Loading branch information
KarkuvelRajan authored Aug 26, 2024
2 parents 45b6c9b + 5aed6ef commit 5d07947
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
<Style TargetType="syncfusion:AnnotationEditor">
<Setter Property="Background" Value="AliceBlue"/>
</Style>

<Style TargetType="syncfusion:Node">
<Setter Property="ShapeStyle">
<Setter.Value>
<Style TargetType="Path">
<Setter Property="Fill" Value="SkyBlue"/>
<Setter Property="Fill" Value="{Binding Path=FillColor, Mode=TwoWay}"/>
<Setter Property="Stretch" Value="Fill"/>
<Setter Property="Stroke" Value="Yellow"/>
<Setter Property="Stroke" Value="{Binding Path=StrokeColor, Mode=TwoWay}"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
</Setter.Value>
</Setter>
</Style>

<Style TargetType="Shape" x:Key="shape">
<Setter Property="Stroke" Value="Black"/>
<Setter Property="StrokeThickness" Value="1"/>
Expand Down Expand Up @@ -71,5 +71,7 @@
<syncfusion:PropertyGrid Grid.Column="1" x:Name="propertyGrid1" Height="600" Width="300"></syncfusion:PropertyGrid>
<syncfusion:SfDiagram Grid.Column="0" Width="600" x:Name="diag">
</syncfusion:SfDiagram>
<Button Content="Draw Node" HorizontalAlignment="Left" Margin="113,10,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<Button Content="Draw Connector" HorizontalAlignment="Left" Margin="222,8,0,0" VerticalAlignment="Top" Click="Button_Click_1"/>
</Grid>
</Window>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Syncfusion.UI.Xaml.Diagram;
using Syncfusion.UI.Xaml.Diagram.Controls;
using Syncfusion.Windows.Shared;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -23,11 +24,11 @@ namespace tesing_node
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
{
public MainWindow()
{
InitializeComponent();
ObservableCollection<NodeViewModel> nodes = new ObservableCollection<NodeViewModel>();
ObservableCollection<CustomNodeViewModel> nodes = new ObservableCollection<CustomNodeViewModel>();
AnnotationEditorViewModel a2 = new AnnotationEditorViewModel()
{
Content = "hi",
Expand All @@ -36,13 +37,15 @@ public MainWindow()
Constraints = AnnotationConstraints.Default,
};
ObservableCollection<ConnectorViewModel> connectors = new ObservableCollection<ConnectorViewModel>();
NodeViewModel n2 = new NodeViewModel()
CustomNodeViewModel n2 = new CustomNodeViewModel()
{
UnitWidth = 100,
UnitHeight = 100,
OffsetX = 100,
OffsetY = 100,
Shape = new RectangleGeometry() { Rect = new Rect(0, 0, 10, 10) },
FillColor = new SolidColorBrush(Colors.SkyBlue),
StrokeColor = new SolidColorBrush(Colors.Green),
Annotations = new ObservableCollection<IAnnotation>()
{
a2,
Expand All @@ -55,22 +58,24 @@ public MainWindow()
UnitWidth = 60,
Constraints = AnnotationConstraints.Default,
};
NodeViewModel n3 = new NodeViewModel()
CustomNodeViewModel n3 = new CustomNodeViewModel()
{
UnitWidth = 100,
UnitHeight = 100,
OffsetX = 300,
OffsetY = 300,
FillColor = new SolidColorBrush(Colors.SkyBlue),
StrokeColor = new SolidColorBrush(Colors.Green),
Shape = new RectangleGeometry() { Rect = new Rect(0, 0, 10, 10) },
Annotations = new ObservableCollection<IAnnotation>()
{
a3,
a3,
},
};
ConnectorViewModel c1 = new ConnectorViewModel()
{
SourceNode = n2,
TargetNode = n3,
TargetNode = n3,
};
nodes.Add(n2);
nodes.Add(n3);
Expand All @@ -79,6 +84,16 @@ public MainWindow()
diag.Connectors = connectors;
(diag.Info as IGraphInfo).ItemSelectedEvent += MainWindow_ItemSelectedEvent;
(diag.Info as IGraphInfo).AnnotationChanged += MainWindow_AnnotationChanged;
(diag.Info as IGraphInfo).ItemAdded += MainWindow_ItemAdded;
}

private void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args)
{
if (args.Item is CustomNodeViewModel)
{
(args.Item as CustomNodeViewModel).FillColor = new SolidColorBrush(Colors.Red);
(args.Item as CustomNodeViewModel).StrokeColor = new SolidColorBrush(Colors.Black);
}
}

private void MainWindow_AnnotationChanged(object sender, ChangeEventArgs<object, AnnotationChangedEventArgs> args)
Expand All @@ -88,7 +103,7 @@ private void MainWindow_AnnotationChanged(object sender, ChangeEventArgs<object,
propertyGrid1.SelectedObject = args.Item;
}
}

void MainWindow_ItemSelectedEvent(object sender, DiagramEventArgs args)
{
if (args.Item is INode)
Expand All @@ -100,5 +115,58 @@ void MainWindow_ItemSelectedEvent(object sender, DiagramEventArgs args)
propertyGrid1.SelectedObject = args.Item;
}
}

private void Button_Click(object sender, RoutedEventArgs e)
{
if (diag.Tool == Tool.MultipleSelect)
{
diag.Tool |= Tool.DrawOnce;
}
diag.DefaultConnectorType = ConnectorType.Line;
diag.DrawingTool = DrawingTool.Rectangle;

}



private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (diag.Tool == Tool.MultipleSelect)
{
diag.Tool |= Tool.DrawOnce;
}
diag.DefaultConnectorType = ConnectorType.Line;
diag.DrawingTool = DrawingTool.Connector;
}
}

public class CustomNodeViewModel : NodeViewModel
{
private Brush fill;

private Brush stroke;


// Fill property
public Brush FillColor
{
get { return fill; }
set
{
fill = value;
OnPropertyChanged("FillColor");
}
}

// Stroke property
public Brush StrokeColor
{
get { return stroke; }
set
{
stroke = value;
OnPropertyChanged("StrokeColor");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>

<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -88,7 +87,6 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>

<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -99,7 +97,6 @@
<None Include="App.config" />
<PackageReference Include="Syncfusion.PropertyGrid.WPF" Version="*" />
<PackageReference Include="Syncfusion.SfDiagram.WPF" Version="*" />
<PackageReference Include="Syncfusion.Themes.Office2019Colorful.WPF" Version="*" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<Compile Include="MainWindow.xaml.cs" />
<PackageReference Include="Syncfusion.PropertyGrid.WPF" Version="*" />
<PackageReference Include="Syncfusion.SfDiagram.WPF" Version="*" />
<PackageReference Include="Syncfusion.Themes.Office2019Colorful.WPF" Version="*" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<Compile Include="MainWindow.xaml.cs" />
<PackageReference Include="Syncfusion.PropertyGrid.WPF" Version="*" />
<PackageReference Include="Syncfusion.SfDiagram.WPF" Version="*" />
<PackageReference Include="Syncfusion.Themes.Office2019Colorful.WPF" Version="*" />
</ItemGroup>
<ItemGroup>
<Page Include="MainWindow.xaml">
Expand Down

0 comments on commit 5d07947

Please sign in to comment.