I have the following XAML
<ListView x:Name="listViewTarget" Height="560" Canvas.Left="10" Canvas.Top="101" Width="924" AllowDrop="True">
<ListView.View>
<GridView>
<GridViewColumn Width="350" Header="File or Email">
</GridViewColumn>
<GridViewColumn Width="500" Header="Awaiting Item" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Width="350" x:Name="cboAI" HorizontalAlignment="Right">
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
The ListView has two columns, in the second column I need a combobox of options.
I have a drag drop event associated with the ListView, when you drag a file onto the list the filenames are dynamically added successfully to the list view.
def listView_drag_drop(sender, e):
data = e.Data.GetData(DataFormats.FileDrop, False)
for s in data:
sender.Items.Add(s)
lstViewDropTarget = LogicalTreeHelper.FindLogicalNode(_tikitSender,listViewTarget')
lstViewDropTarget.Drop += listView_drag_drop
What I need to do inside that event is to also populate the combobox, which is currently empty.
I have tried to work out how to get a reference to the combobox to be able to set its ItemsSource property, but after days of effort I have failed.
I am new to IronPython and appreciate your help.
EDIT: I tried many ways of getting a reference to the combo without success.
Now I am trying to use the Loaded event, but I get an error :
Failed to create a 'Loaded' from the text 'ComboBox_Loaded'
<ListView x:Name="listViewTarget" Height="560" Canvas.Left="10" Canvas.Top="101" Width="924" AllowDrop="True">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="test">
<Label x:Name="textFileName" Content="ABC" />
<TextBlock Text="DEF"/>
<ComboBox
HorizontalAlignment="Left"
Margin="10,10,0,0"
VerticalAlignment="Top"
Width="120"
Loaded="ComboBox_Loaded"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
In Iron Python I define the event:
def ComboBox_Loaded(sender, e):
MessageBox.Show("Test")
EDIT 2: Now I am trying to use the ListView CollectionChanged event
lstViewDropTarget.Items.CollectionChanged += ListView_ItemChanged
And here is the event code
def ListView_ItemChanged(sender, e):
MessageBox.Show(e.NewItems.Count.ToString())
That works messagebox shows '1'
So I can access the new item using e.NewItems[0]
But how do I access the controls?!
I try:
MessageBox.Show(e.NewItems[0].Children.Count.ToString())
and that fails to execute so I try:
MessageBox.Show(e.NewItems[0].Content.Children.Count.ToString())
that also fails
I am very fed up, I cant believe its so very very hard