2013-03-18 54 views
0

我對我的IsEnabled和IsChecked屬性有一個多觸發器。除了在複選框被禁用之後,它不會重新啓用代碼。這裏是XAML:如何重新啓用在WPF中綁定列表視圖中的複選框?

<ListView ScrollViewer.ScrollChanged="lstRewardsEarned_ScrollChanged" Height="178" HorizontalAlignment="Left" Margin="12,0,0,81" Name="lstRewardsEarned" VerticalAlignment="Bottom" Width="327" SelectionMode="Multiple" Background="White" FontFamily="Calibri" FontSize="16"> 
    <ListView.ItemContainerStyle> 
     <Style TargetType="{x:Type ListViewItem}"> 

      <!-- bind content IsSelected to the ListViewItem IsChecked --> 
      <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=Explicit}" /> 

      <!-- bind content IsEnabled to the ListViewItem IsEnabled --> 
      <Setter Property="IsEnabled" Value="{Binding Path=IsEnabled, Mode=TwoWay, UpdateSourceTrigger=Explicit}" /> 

      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="ListBoxItem"> 
         <Border x:Name="Border" SnapsToDevicePixels="true"> 
          <ContentPresenter /> 
         </Border> 

         <ControlTemplate.Triggers> 

          <!--Highlight if IsSelected and IsEnabled--> 
          <MultiTrigger> 
           <MultiTrigger.Conditions> 
            <Condition Property="IsSelected" Value="True"/> 
            <Condition Property="IsEnabled" Value="True"/> 
           </MultiTrigger.Conditions> 
           <MultiTrigger.Setters> 
            <Setter TargetName="Border" Property="Background" Value="Cyan"/> 
           </MultiTrigger.Setters> 
          </MultiTrigger> 

          <!--Remove highlight if is not Selected and IsEnabled--> 
          <MultiTrigger> 
           <MultiTrigger.Conditions> 
            <Condition Property="IsSelected" Value="False"/> 
            <Condition Property="IsEnabled" Value="True"/> 
           </MultiTrigger.Conditions> 
           <MultiTrigger.Setters> 
            <Setter TargetName="Border" Property="Background" Value="Transparent"/> 
           </MultiTrigger.Setters> 
          </MultiTrigger> 

          <!--Add a trigger to remove the highlighting if IsEnabled is changed to false--> 
          <Trigger Property="IsEnabled" Value="False"> 
           <Setter TargetName="Border" Property="Background" Value="Transparent"/> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </ListView.ItemContainerStyle> 
</ListView> 

這是代碼重新啓用的複選框:

For Each checkBox As CheckBox In lstRewardsEarned.Items 
    checkBox.IsEnabled = true 

    'This writes out false! 
    Console.WriteLine(checkBox.IsEnabled) 
Next 

在此先感謝。

回答

0

將UpdateSourceTrigger移出IsEnabled和IsSelected屬性綁定?

According to MSDN

如果設置UpdateSourceTrigger值顯式,則必須調用 的UpdateSource方法或更改將不會傳播回 源。

+0

謝謝馬特。我試着拿出UpdateSourceTrigger = Explicit,它沒有效果。我應該提出一個IsEnabled事件還是修改其他東西? – 2013-03-19 13:26:01

相關問題