UWP DRAWING XAML
<Page
x:Class="UWPNetWork.Scenario1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPNetWork"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="Root" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" AutomationProperties.Level="-3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel>
<TextBox x:Name="tb1" Height="40" />
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<Button x:Name="Line" Content="Line Draw" Click="Line_Click" />
<Button x:Name="Bus" Content="Busbar Draw" Click="Bus_Click" />
<Button x:Name="Circle" Content="Circle Draw" Click="Circle_Click" />
<Button x:Name="Save" Content="Save Drawing" Click="Save_Click" />
<Button x:Name="Load" Content="Load Drawing" Click="Load_Click" />
<Button x:Name="Text" Content="Write Text" Click="Text_Click" />
</StackPanel>
</StackPanel>
<Grid x:Name="root" Width="1714" Height="1103" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Image x:Name="simple" Width="1714" Height="1103" />
</Grid>
</StackPanel>
</Grid>
</Page>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPNetWork"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="Root" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" AutomationProperties.Level="-3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel>
<TextBox x:Name="tb1" Height="40" />
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<Button x:Name="Line" Content="Line Draw" Click="Line_Click" />
<Button x:Name="Bus" Content="Busbar Draw" Click="Bus_Click" />
<Button x:Name="Circle" Content="Circle Draw" Click="Circle_Click" />
<Button x:Name="Save" Content="Save Drawing" Click="Save_Click" />
<Button x:Name="Load" Content="Load Drawing" Click="Load_Click" />
<Button x:Name="Text" Content="Write Text" Click="Text_Click" />
</StackPanel>
</StackPanel>
<Grid x:Name="root" Width="1714" Height="1103" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Image x:Name="simple" Width="1714" Height="1103" />
</Grid>
</StackPanel>
</Grid>
</Page>
UWP DEMONSTRATIONS
UWP DRAWING LINE TEXT CIRCLE
private void Root_PointerPressed(object sender, PointerRoutedEventArgs e)
{
if (line1)
{
key = 1;
lX1 = e.GetCurrentPoint(root).Position.X;
lY1 = e.GetCurrentPoint(root).Position.Y;
line1 = false;
bar1 = false;
circle1 = false;
}
if (bar1)
{
key = 2;
rX1 = e.GetCurrentPoint(root).Position.X;
rY1 = e.GetCurrentPoint(root).Position.Y;
line1 = false;
bar1 = false;
circle1 = false;
}
if (circle1)
{
point = new Point();
ellipse = new Ellipse();
ellipse.Height = 40;
ellipse.Width = 40;
Canvas.SetLeft(ellipse, (int)e.GetCurrentPoint(root).Position.X);
Canvas.SetTop(ellipse, (int)e.GetCurrentPoint(root).Position.X);
ellipse.StrokeThickness = 2;
ellipse.Stroke = new SolidColorBrush(Windows.UI.Colors.Green);
point.X = e.GetCurrentPoint(root).Position.X;
point.Y = e.GetCurrentPoint(root).Position.Y;
// ellipse.RenderTransform.GetValue(new Point(point.X, point.Y);
TranslateTransform translateTransform = new TranslateTransform();
translateTransform.X = point.X-860 ;
translateTransform.Y = point.Y-550 ;
transformGroup = new TransformGroup();
transformGroup.Children.Add(translateTransform);
ellipse.RenderTransform = transformGroup;
root.Children.Add(ellipse);
line1 = false;
bar1 = false;
circle1 = false;
text1 = false;
}
if (text1)
{
text = new TextBlock();
new TextBlock();
text.Text = tb1.Text;
text.Foreground = new SolidColorBrush(Windows.UI.Colors.Green);
point.X = e.GetCurrentPoint(root).Position.X;
point.Y = e.GetCurrentPoint(root).Position.Y - 10;
TranslateTransform translateTransform = new TranslateTransform();
translateTransform.X = point.X;
translateTransform.Y = point.Y;
transformGroup = new TransformGroup();
transformGroup.Children.Add(translateTransform);
text.RenderTransform = transformGroup;
root.Children.Add(text);
}
}
private void Root_PointerMoved(object sender, PointerRoutedEventArgs e)
{
if (key == 1)
{
root.Children.Remove(line);
line = new Line();
line.Stroke = new SolidColorBrush(Windows.UI.Colors.RoyalBlue);
line.StrokeThickness = 2;
line.X1 = lX1;
line.Y1 = lY1;
line.X2 = e.GetCurrentPoint(root).Position.X;
line.Y2 = e.GetCurrentPoint(root).Position.Y;
root.Children.Add(line);
}
if (key == 2)
{
root.Children.Remove(line0);
line0 = new Line();
line0.Stroke = new SolidColorBrush(Windows.UI.Colors.Green);
line0.StrokeThickness = 8;
line0.X1 = rX1;
line0.Y1 = rY1;
line0.X2 = e.GetCurrentPoint(root).Position.X;
line0.Y2 = e.GetCurrentPoint(root).Position.Y;
root.Children.Add(line0);
}
}
private void Root_PointerReleased(object sender, PointerRoutedEventArgs e)
{
if (key == 1)
{
key = 0;
line = new Line();
line.Stroke = new SolidColorBrush(Windows.UI.Colors.RoyalBlue);
line.StrokeThickness = 2;
line.X1 = lX1;
line.Y1 = lY1;
line.X2 = e.GetCurrentPoint(root).Position.X;
line.Y2 = e.GetCurrentPoint(root).Position.Y;
root.Children.Add(line);
}
if (key == 2)
{
key = 0;
line0 = new Line();
line0.Stroke = new SolidColorBrush(Windows.UI.Colors.Green);
line0.StrokeThickness = 8;
line0.X1 = rX1;
line0.Y1 = rY1;
line0.X2 = e.GetCurrentPoint(root).Position.X;
line0.Y2 = e.GetCurrentPoint(root).Position.Y;
root.Children.Add(line0);
}
}
private void Text_Click(object sender, RoutedEventArgs e)
{
text1 = true;
line1 = false;
bar1 = false;
circle1 = false;
}
private void Line_Click(object sender, RoutedEventArgs e)
{
line1 = true;
bar1 = false;
circle1 = false;
text1 = false;
}
private void Bus_Click(object sender, RoutedEventArgs e)
{
bar1 = true;
line1 = false;
circle1 = false;
text1 = false;
}
private void Circle_Click(object sender, RoutedEventArgs e)
{
circle1 = true;
line1 = false;
bar1 = false;
text1 = false;
}

Comments
Post a Comment