Hello stackoverflowers,
I would like to set property canvas.left on the ListBoxItems of my ListBox. I'm trying this :
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Canvas.Left" Value="{Binding Content.StartPoint.X, Mode=TwoWay, RelativeSource={RelativeSource Self}}"/>
<Setter Property="Canvas.Top" Value="{Binding Content.StartPoint.Y}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ContentPresenter/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
But it says it can't resolve content property in my datacontext.
I tried
<Setter Property="Canvas.Left" Value="{Binding Content.StartPoint.X}, Mode=TwoWay, RelativeSource={RelativeSource Self}}/>
But then it can't resolve StartPoint in datacontext object.
So i wonder how can i bind to the properties of my listbox items ??
EDIT : I'm binding ListBox ItemsSource to an ObservableCollection. The view is a UserControl.
EDIT 2 :
My listbox is binded to an observable collection of objects derivated from Foo.
Foo object defines StartPoint.
public abstract class Foo: INotifyPropertyChanged
{
protected Point m_startPoint;
public double Height { get; set; }
public double Width { get; set; }
public Point StartPoint
{
get { return m_startPoint; }
set
{
m_startPoint = value;
Width = Math.Abs(m_startPoint.X - m_endPoint.X);
Height = Math.Abs(m_startPoint.Y - m_endPoint.Y);
OnPropertyChanged(nameof(StartPoint));
OnPropertyChanged(nameof(Width));
OnPropertyChanged(nameof(Height));
}
}
Content
? is it inside theDataSource
object ofListView
? orViewModel
of the view? – Gopichandartypeof
view? is it aUserControl
orWindow
– GopichandarContent.StartPoint.X
resides. – Gopichandar