Note that there are some explanatory texts on larger screens.

plurals
  1. POItemsControl Binding the Current Object?
    primarykey
    data
    text
    <p>I am just started learning WPF, and trying to learn the correct way to do things. I am using a ItemsControl to bind to an Observable Collection consisting of Points. Each point represents the center of an ellipse. However I am unsure how to bind to the current item, to the center property of the Ellipse Geometry.</p> <pre><code>&lt;EllipseGeometry Center="{Binding Path=????}" RadiusX="10" RadiusY="10"/&gt; </code></pre> <p>However I know it is more or less working, since this gives me the expected output. I just can't figure out how to say the current object. </p> <pre><code>&lt;EllipseGeometry Center="10,10" RadiusX="{Binding Path=X}" RadiusY="{Binding Path=Y}"/&gt; </code></pre> <p>C# Code:</p> <pre><code>public class ViewModel { public ObservableCollection&lt;Point&gt; PointList { get; private set; } public ViewModel() { PointList = new ObservableCollection&lt;Point&gt;(); AddPoint(new Point(10, 10)); AddPoint(new Point(200, 200)); AddPoint(new Point(500, 500)); } public void AddPoint(Point p) { PointList.Add(p); } } </code></pre> <p>XAML Code:</p> <pre><code>&lt;ItemsControl Grid.Row="0" ItemsSource="{Binding Path=PointList}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;Canvas /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Path Fill="Gold" Stroke="Black" StrokeThickness="1" Tag="Hi" &gt; &lt;Path.Data&gt; &lt;EllipseGeometry Center="{Binding Path=????}" RadiusX="10" RadiusY="10"/&gt; &lt;/Path.Data&gt; &lt;/Path&gt; &lt;!--&lt;Rectangle Fill="Red" Width="25" Height="25"/&gt;--&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;ItemsControl.ItemContainerStyle&gt; &lt;Style&gt; &lt;!--&lt;Setter Property="Canvas.Left" Value="{Binding Path=X}"/&gt; &lt;Setter Property="Canvas.Top" Value="{Binding Path=Y}"/&gt;--&gt; &lt;/Style&gt; &lt;/ItemsControl.ItemContainerStyle&gt; &lt;/ItemsControl&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload