I have a ListBox bound to an ObservableCollection, with a canvas as an ItemsPanel. Everything works as expected - I've implemented dragging of the items succesfuly - but the problem is that I can't set the ZIndex of the clicked item. Debuging shows that all the items have a ZIndex of 0, which looks strange to me. What I want is to bring the item to front when clicked and send to back when released. Could someone give me any ideas? Please feel free to ask for any code that might be useful.
Update: This is the ItemsContainerStyle, defined as a Window Resource
<Style x:Key="MediaContainerStyle" TargetType="ListBoxItem">
<Setter Property="Canvas.Left" Value="{Binding MediaPosition.X,UpdateSourceTrigger=PropertyChanged}"/>
<Setter Property="Canvas.Top" Value="{Binding MediaPosition.Y,UpdateSourceTrigger=PropertyChanged}"/>
<Setter Property="Panel.ZIndex" Value="{Binding ZIndex,UpdateSourceTrigger=PropertyChanged}"/>
</Style>
and the template for the item
<DataTemplate x:Key="MediaDataTemplate">
<views:MediaItemView MouseDown="OnMediaItemMouseDown"
MouseMove="OnMediaItemMouseMove"/>
</DataTemplate>
where MediaItemView is a user control.
In the code behind, I do
void OnMediaItemMouseDown(Object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == Pressed)
{
FrameworkElement feItem = sender as FrameworkElement;
MediaViewModel vmItem = feItem.DataContext as MediaViewModel;
vmItem.ZIndex = vm.MainMedia.Count;
// Keep the click point
pClick = e.GetPosition(feItem);
}
}
where vm is an instance of my underlying viewmodel, containing a Double property ZIndex