2013-03-12 117 views
0

我是WPF新手。我有一個WPF列表視圖中的複選框列表。我有功能,當用戶點擊複選框時,它突出顯示該行。所有這一切工作正常。但是,當複選框被禁用時,它仍然會突出顯示該行,並且它也會檢查複選框。我該如何做到這一點,因此它不會突出顯示或檢查用戶何時單擊禁用的複選框?提前致謝。如何禁用在WPF中禁用項目時突出顯示?

<ListView ScrollViewer.ScrollChanged="lstRewardsExpiration_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}"> 
      <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}" /> 

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

         <ControlTemplate.Triggers> 
          <Trigger Property="IsSelected" Value="True"> 
           <Setter TargetName="Border" Property="Background" Value="Cyan"/> 
          </Trigger> 
          <Trigger Property="IsSelected" Value="False"> 
           <Setter TargetName="Border" Property="Background" Value="Transparent"/> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </ListView.ItemContainerStyle> 
</ListView> 
+0

我沒有看到任何代碼複選框你張貼... – Blachshma 2013-03-12 20:51:37

回答

1

您可能需要使用MultiTrigger來得到這個工作

下面是一個例子,如果我讀你的問題正確

<Style TargetType="{x:Type ListViewItem}"> 
    <Setter Property="IsSelected" Value="{Binding Path=IsChecked, Mode=TwoWay}" /> 

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

    <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 higlighting 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> 
+0

這工作完美,非常感謝。 – 2013-03-13 12:52:25

相關問題