Witam,
Co prawda temat sugeruje kilka problemów, ale wątek - mam nadzieję - będzie rozwijany wraz z postępem mojej wiedzy. :)
Co chcę zrobić:
- wczytać dane z kilku list, z których każda opisuje rodzaj obiektu (kółko, kwadrat), jego kolor oraz nazwę,
- obiekty mają być "przesuwalne", obraz ma być skalowany bez skali wielkości elementów,
- po kliknięciu na obiekt dane (nazwa) powinna być ładowana do kontrolek.
Utknąłem na samym początku, prosty kod - niestey nie działa :(
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<Rect> lista = new List<Rect>();
Rect r1 = new Rect();
r1.x = 200; r1.y = 200; r1.name = "rec1";
Rect r2 = new Rect();
r2.x = 300; r2.y = 250; r2.name = "rec2";
lista.Add(r1);
lista.Add(r2);
}
}
public class Rect
{
public double x { set; get; }
public double y { set; get; }
public string name { set; get; }
}
XAML:
<Grid>
<ItemsControl ItemsSource="{Binding list}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Width="20" Height="20" Fill="Black">
<Rectangle.RenderTransform>
<TranslateTransform X="{Binding x}" Y="{Binding y}"/>
</Rectangle.RenderTransform>
</Rectangle>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>