2013-07-12 41 views
0

在我的View類中,我有一個listbox控件。它包括文本框和組合框的堆疊面板。但我不明白的是,當我運行應用程序時,列表框的數據被刪除了?如果我想避免這種情況,我應該怎麼做?爲什麼listbox在運行時總是可編輯的?

我希望列表框內容可編輯,當我點擊我的窗口的編輯按鈕。 請也建議我使列表框內容可編輯的方法。

我的列表框是

<ListBox x:Name="listBox1" ItemsSource="{Binding}" Margin="0,131,0,59" ItemTemplateSelector="{StaticResource templateSelector}" SelectionMode="Single"/> 

<!-- Default DataTemplate --> 
     <DataTemplate x:Key="DefaultDataTemplate" > 
      <StackPanel Orientation="Horizontal" Width="596"> 
       <TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/> 
       <TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/> 
       <TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/> 
       <TextBox Text="{Binding StopTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/> 
       <TextBox Text="{Binding TaskNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="71"/> 
       <TextBox Text="{Binding ProjectNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/> 
      </StackPanel> 
     </DataTemplate> 

     <!-- Editable DataTemplate --> 
     <DataTemplate x:Key="EditableDataTemplate"> 
       <StackPanel Orientation="Horizontal" Width="596"> 
       <!--<ComboBox x:Name="ClientComboBox" SelectionChanged="ClientComboBoxChanged" ItemsSource="{Binding Path=clientList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ClientNameBindingClass, Mode=OneWayToSource}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="145"/>--> 
       <TextBox Text="{Binding ClientNameBinding,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/> 
       <TextBox Text="{Binding ApplicationNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/> 
       <TextBox Text="{Binding StartTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/> 
       <TextBox Text="{Binding StopTimeBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/> 
       <TextBox Text="{Binding TaskNameBinding}" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/> 
       <ComboBox x:Name="ProjectComboBox" SelectionChanged="ProjectComboBoxChanged" ItemsSource="{Binding Path=projectList, ElementName=MainWin}" SelectedValuePath="_id" DisplayMemberPath="_name" SelectedItem="{Binding ProjectNameBindingClass, Mode=OneWayToSource}" Width="71" Background="Yellow" BorderThickness="0"/> 
      </StackPanel> 
     </DataTemplate> 


     <!-- DataTemplate Selector --> 

     <l:DayViewListDataTemplateSelector x:Key="templateSelector" 
      DefaultDataTemplate="{StaticResource DefaultDataTemplate}" 
      EditableDataTemplate="{StaticResource EditableDataTemplate}"/> 
+1

開始獲取要顯示的數據。懷疑您的裝訂有問題。可能會幫助您找到問題PresentationTraceSources.TraceLevel =「高」。對於非編輯可以使用IsReadonly = true或TextBlock。 – Paparazzi

+0

謝謝,Blam。使用TextBlock代替TextBox解決了我的問題。 – Dinesh

回答

0

對於非編輯可以使用IsReadonly = true或一個TextBlock。

相關問題