C# listview的Datatemplate中的ComboBox无法正常工作
“Listview”的“DataTemplate”中的“ComboBox”无法正常工作C# listview的Datatemplate中的ComboBox无法正常工作,c#,wpf,C#,Wpf,“Listview”的“DataTemplate”中的“ComboBox”无法正常工作 <ComboBox x:Name="colTopics" Width="100" Height="30" SelectedValue="{Binding SELECTEDTOPICProperty}" Margin="31,333,317,10"> <ComboBoxItem Content="eyteeee"/> <ComboBoxItem C
<ComboBox x:Name="colTopics" Width="100" Height="30" SelectedValue="{Binding SELECTEDTOPICProperty}" Margin="31,333,317,10">
<ComboBoxItem Content="eyteeee"/>
<ComboBoxItem Content="eyteyte"/>
</ComboBox>
如果此“组合框”位于“ListView”的“DataTemplate”中,“SelectedValue”(是属性“SELECTEDTOPICProperty”)的绑定将给出“null”值。DataTemplate中的组合框是动态生成的
<ListView x:Name="gridTopics" BorderThickness="2" ItemsSource="{Binding Path=TOPICSINFO}" HorizontalAlignment="Left" Margin="91,79,0,0" VerticalAlignment="Top" Height="242" Width="310" BorderBrush="#FF32A3D6" >
<ListView.Effect>
<DropShadowEffect Color="#FF9ADDFB"/>
</ListView.Effect>
<ListView.View>
<GridView >
<GridView.Columns>
<GridViewColumn x:Name="colPageNo" DisplayMemberBinding="{Binding PAGENO}" Width="50" Header="Pages" />
<GridViewColumn x:Name="colListTopics" Width="241" Header="Associated Topics" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="colTopics" Width="100" Height="30" SelectedValue="{Binding SELECTEDTOPICProperty}" Margin="31,333,317,10">
<ComboBoxItem Content="eyteeee"/>
<ComboBoxItem Content="eyteyte"/>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
如果“ComboBox”不在“ListView”中,它工作正常,并且在属性“SELECTEDTOPICProperty”中有选定值。
public class TopicsInfo
{
public TopicsInfo()
{
listTopics = new List<string>();
}
private string pageNo;
public string PAGENO
{
get { return pageNo; }
set { pageNo = value; }
}
private List<string> listTopics;
public List<string> LISTTOPICS
{
get { return listTopics; }
set { listTopics = value; }
}
private string selectedTopicString;
public string SELECTEDTOPICProperty
{
get { return selectedTopicString; }
set
{
selectedTopicString = value;
}
}
}
公共类主题信息
{
公共主题信息()
{
listTopics=新列表();
}
私有字符串pageNo;
公共字符串页码
{
获取{return pageNo;}
设置{pageNo=value;}
}
私人列表主题;
公共列表主题
{
获取{返回listTopics;}
设置{listTopics=value;}
}
私有字符串selectedTopicString;
公共字符串SELECTEDTOPICProperty
{
获取{return selectedTopicString;}
设置
{
selectedTopicString=值;
}
}
}
如果可能的话,他们会尝试像这样重新构造代码
你的财产类别
public class TopicsInfo
{
private string pageNo;
public string PAGENO
{
get { return pageNo; }
set { pageNo = value; }
}
private string selectedTopicString;
public string SELECTEDTOPICProperty
{
get { return selectedTopicString; }
set
{
selectedTopicString = value;
}
}
}
要与ListView绑定的属性
private ObservableCollection<TopicsInfo> topicsInfoCollection = new ObservableCollection<TopicsInfo>();
public ObservableCollection<TopicsInfo> TopicsInfoCollection
{
get
{
return this.topicsInfoCollection;
}
set
{
this.topicsInfoCollection = value;
}
}
private ObservableCollection topicsInfoCollection=new ObservableCollection();
公共可观测集合主题信息集合
{
收到
{
返回此.topicsInfoCollection;
}
设置
{
this.topicsInfoCollection=值;
}
}
还有你的XAML代码
<ListView x:Name="gridTopics" BorderThickness="2" ItemsSource="{Binding Path=TopicsInfoCollection}" HorizontalAlignment="Left" Margin="91,79,0,0" VerticalAlignment="Top" Height="242" Width="310" BorderBrush="#FF32A3D6" >
<ListView.Effect>
<DropShadowEffect Color="#FF9ADDFB"/>
</ListView.Effect>
<ListView.View>
<GridView >
<GridView.Columns>
<GridViewColumn x:Name="colPageNo" DisplayMemberBinding="{Binding PAGENO}" Width="50" Header="Pages" />
<GridViewColumn x:Name="colListTopics" Width="241" Header="Associated Topics" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="colTopics" Width="100" Height="30" SelectedValue="{Binding SELECTEDTOPICProperty}" Margin="31,333,317,10">
<ComboBoxItem Content="eyteeee"/>
<ComboBoxItem Content="eyteyte"/>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
您能给我看一下“TOPICSINFO”和“SELECTEDTOPICProperty”的详细信息吗?“SELECTEDTOPICProperty”是“TOPICSINFO”的属性吗?感谢您的回复,原始问题中添加了代码。