2013-12-17 73 views
1

「ListView」的「DataTemplate」中的「組合框」無法正常工作。ListView的Datatemplate內的組合框無法正常工作

<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」)給出了「空」值。 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> 

它工作正常,並有選擇的屬性「SELECTEDTOPICProperty」的值,如果「組合框」不在「的ListView」。

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; 
     } 
    } 
} 
+1

你能告訴我「TOPICSINFO」和「SELECTEDTOPICProperty」的細節嗎? 「SELECTEDTOPICProperty」是「TOPICSINFO」的屬性嗎? –

+0

感謝您的回覆,Code添加到原始問題中。 – Ahsan

回答

0

嘿嘗試重組這樣如果可能的話你的代碼,

你的財產類,

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; 
      } 
     } 

和你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> 
相關問題