Dynamické kreslenie čiar vo WPF   zodpovězená otázka

WPF

Dobrý večer.

Mám nakreslenú čiaru

1
2
3
4
5
6
7
8
9
10
11
12
<Window x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Line
    X1="100" Y1="50"
    X2="300" Y2="50"
    Stroke="Black"
    StrokeThickness="1" />
    </Grid>
</Window>

Ako pridám pod ňou ďalšie čiary z programu?

nahlásit spamnahlásit spam 0 odpovědětodpovědět

Tak už som na to prišiel.

Do XAML pridame canvas1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Window x:Class="WpfApplication3.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Canvas Height="214" HorizontalAlignment="Left" Margin="12,12,0,0" Name="canvas1" VerticalAlignment="Top" Width="479" >
            <Line
    X1="100" Y1="50"
    X2="300" Y2="50"
    Stroke="Black"
    StrokeThickness="1" />
        </Canvas>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="358,266,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    </Grid>
    
</Window>

a XAML.cs môže vyzerať trebárs takto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace WpfApplication3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
         
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 6; i++)
            {
                Shape ciara = null;
                ciara = new Line() { X1 = 100, Y1 = 50 + 10 * i, X2 = 300, Y2 = 50 + 10 * i };
 
                ciara.Stroke = SystemColors.WindowTextBrush;
                canvas1.Children.Add(ciara);
                 
            }         
          
        }
    }
}
nahlásit spamnahlásit spam 0 odpovědětodpovědět

přihlásit pomocí externího účtu

přihlásit pomocí jména a hesla

Uživatel:
Heslo:

zapomenuté heslo

 

založit nový uživatelský účet

zaregistrujte se

 
zavřít

Nahlásit spam

Opravdu chcete tento příspěvek nahlásit pro porušování pravidel fóra?

Nahlásit Zrušit

Chyba

zavřít

feedback