I have a ListView containing objects and I have used a GridView to display the properties:
<ListView ItemsSource="{Binding Path=Fields}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewMouseLeftButtonDown" Handler="s_PreviewMouseLeftButtonDown" />
<EventSetter Event="PreviewMouseLeftButtonUp" Handler="s_PreviewMouseLeftButtonUp" />
<EventSetter Event="MouseMove" Handler="MouseMoveHandler" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView >
<GridViewColumn Header="1" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Textbox text={binding} />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Then I have a drag and drop behavior set up on the ListView so that when an ListViewItem is dragged, I clone the controls template which becomes the drag adorner:
private static ContentControl CreateClone(ListViewItem element)
{
ListViewItem control = new ListViewItem();
if (element != null)
{
control.Content = element.Content;
control.ContentTemplate = element.ContentTemplate;
control.Template = element.Template;
control.Style = element.Style;
control.Background = Brushes.LightGray;
control.Width = element.ActualWidth;
control.Height = (element.ActualHeight);
control.VerticalAlignment = VerticalAlignment.Top;
control.VerticalContentAlignment = VerticalAlignment.Stretch;
control.HorizontalContentAlignment = HorizontalAlignment.Stretch;
control.Opacity = .70;
}
return control;
}
My problem is that the ListViewItem does not have a ContenetTemplate, because im assuming it is defined by the GridView, So I end up with a blank adorner with no columns in it. Do I need to also define a template in the ItemContainerStyle?