//************************************** // Name: line drawing // Description:line drawing function in code using wpf // By: T J Betz // // // Inputs:None // // Returns:None // //Assumes:None // //Side Effects:None //************************************** XAML code// <Window x:Class="project.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:project" mc:Ignorable="d" Title ="MAIN WINDOW" Height="350" Width="350" Background="LightYellow" Loaded="Window_Loaded" > <Grid> <Canvas Name="can" Margin="15,15,15,15" /> </Grid> </Window> XAMLcs code// using System; using System.Windows; using System.Windows.Media; using System.Windows.Shapes; namespace project { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { for (int b = 0; b <30; b++) { Line line = new Line(); can.Children.Add(line); line.StrokeThickness = 2; line.Stroke = Brushes.Blue; line.X1 = 150 +120 * Math.Cos(6.28 * b / 30); line.Y1 = 130 +120 * Math.Sin(6.28 * b / 30); line.X2 = 150 +40 *Math.Cos(6.28 * b / 30); line.Y2 = 130 +40 * Math.Sin(6.28 * b / 30); } } } }