-3

XAML/View

<ItemsControl ItemsSource="{Binding _shapes}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas Width="800" Height="600"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Ellipse Width="{Binding width}" Height="{Binding height}" Fill="{Binding brush}">
                    <Ellipse.RenderTransform>
                        <TranslateTransform X="{Binding x}" Y="{Binding y}"/>
                    </Ellipse.RenderTransform>
                </Ellipse>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

MainViewModel

public ObservableCollection<GalaxyObjectShape> _shapes { get; set; }

GalaxyObjectShape

public class GalaxyObjectShape
    {
        public string name;
        public System.Windows.Media.Brush brush;
        public double x;
        public double y;
        public double vx;
        public double vy;
        public double height;
        public double width;
    }

Could anyone perhaps help me look why this doesn't work? Getting these errors in output, have tried everything that I could find on this error:

System.Windows.Data Error: 40 : BindingExpression path error: 'width' property not found on 'object' ''GalaxyObjectShape' (HashCode=407659)'. BindingExpression:Path=width; DataItem='GalaxyObjectShape' (HashCode=407659); target element is 'Ellipse' (Name=''); target property is 'Width' (type 'Double')
System.Windows.Data Error: 40 : BindingExpression path error: 'height' property not found on 'object' ''GalaxyObjectShape' (HashCode=407659)'. BindingExpression:Path=height; DataItem='GalaxyObjectShape' (HashCode=407659); target element is 'Ellipse' (Name=''); target property is 'Height' (type 'Double')
System.Windows.Data Error: 40 : BindingExpression path error: 'brush' property not found on 'object' ''GalaxyObjectShape' (HashCode=407659)'. BindingExpression:Path=brush; DataItem='GalaxyObjectShape' (HashCode=407659); target element is 'Ellipse' (Name=''); target property is 'Fill' (type 'Brush')
System.Windows.Data Error: 40 : BindingExpression path error: 'x' property not found on 'object' ''GalaxyObjectShape' (HashCode=407659)'. BindingExpression:Path=x; DataItem='GalaxyObjectShape' (HashCode=407659); target element is 'TranslateTransform' (HashCode=3668935); target property is 'X' (type 'Double')
System.Windows.Data Error: 40 : BindingExpression path error: 'y' property not found on 'object' ''GalaxyObjectShape' (HashCode=407659)'. BindingExpression:Path=y; DataItem='GalaxyObjectShape' (HashCode=407659); target element is 'TranslateTransform' (HashCode=3668935); target property is 'Y' (type 'Double')

My other bindings like:

Title="{Binding mainWindowTitle}"

For my window do work (mainWindowTitle is a simple string in the same ViewModel)

Strah Behry
  • 551
  • 2
  • 8
  • 25

1 Answers1

0

{get; set;} on properties in GalaxyObjectShape oops...

Strah Behry
  • 551
  • 2
  • 8
  • 25