I am trying to create a canvas with elements located in special places on canvast, since I cannot link the source and template directly to Canvas, I used ItemControl. But there is a problem that all items are at 0.0. And I tested the bindings that they do not return 0,0. How can I do this work so that the elements are in the right place?
It is also permissible to create 2 layers on the canvas, where each layer is tied to a different source and uses a different template?
This is in Silverlight
<ItemsControl Grid.Row="1" Grid.Column="1" Width="650" Height="650" ItemsSource="{Binding Skills}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas Margin="0" Width="650" Height="650" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Canvas.Top="{Binding Top}" Canvas.Left="{Binding Left}"> <TextBlock Text="{Binding Name}" /> <Image Source="{Binding Icon}" /> <StackPanel Orientation="Horizontal" > <TextBlock FontWeight="Bold" TextAlignment="Center" Text="{Binding SkillPointsStatusText}" /> </StackPanel> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
Test with ItemContainerStyle
<ItemsControl Grid.Row="1" Grid.Column="1" Width="650" Height="650" ItemsSource="{Binding Skills}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas Margin="0" Width="650" Height="650" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding Name}" /> <Image Source="{Binding Icon}" /> <TextBlock FontWeight="Bold" TextAlignment="Center" Text="{Binding SkillPointsStatusText}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.Top" Value="{Binding Top}" /> <Setter Property="Canvas.Left" Value="{Binding Left}" /> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl>
Well, I chose a project, but I will leave the question open if you have anwser
data-binding wpf silverlight xaml
Androme
source share