2013-06-12 21 views
1

嗨我在應用主題ThemeExpressionDark.xaml時出現複選框不顯示在ListView中的問題。ListView複選框在WPF中應用主題時不顯示

我有查看模型中的集合。這些收集項目將與ListView內的複選框綁定。

我在XAML for ListView中的代碼是這樣的。對於複選框的DataTemplate

<ListView Background="Transparent" x:Name="checkedListView" SelectionMode="Multiple" ItemsSource="{Binding CollectionOfDays}" ItemTemplate="{StaticResource ItemDataTemplate}"  CheckBox.Unchecked="OnUncheckItem" SelectionChanged="SelectDays" SelectedItem="{Binding SelectedItems}"> 

XAML代碼和主題我用這是page.Resource是這樣

<Page.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/Skins/ThemeExpressionDark.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
     <Style x:Key="ListViewTransparentSelection_Both" TargetType="{x:Type ListViewItem}"> 
      <Style.Resources> 
       <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/> 
       <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/> 
      </Style.Resources> 
     </Style> 
     <local:UriToBitmapConverter x:Key="UriToBitmapConverter" />  
     <DataTemplate x:Key="ItemDataTemplate"> 
      <CheckBox 
     x:Name="checkbox" Foreground="Wheat" Content="{Binding}" Margin="10,0,0,0" 
     Command="{Binding CheckBoxCommand}" CommandParameter="{Binding ElementName=checkedListView, Path=SelectedItems}" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Path=IsSelected}" /> 
     </DataTemplate>    
    </ResourceDictionary> 
</Page.Resources> 

當我執行此XAML代碼集合ListView控件中的複選框不顯示。請讓我知道是否使用DataTemplate或主題的問題。

以下是我的主題ThemeExpressionDark.xaml中與複選框相關的XAML代碼。

<Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}" 
     TargetType="{x:Type CheckBox}"> 
    <Setter Property="FontSize" 
      Value="10" /> 
    <Setter Property="SnapsToDevicePixels" 
      Value="true" /> 
    <Setter Property="FocusVisualStyle" 
      Value="{DynamicResource CheckBoxFocusVisual}" /> 
    <Setter Property="Background" 
      Value="{DynamicResource NormalBrush}" /> 
    <Setter Property="BorderBrush" 
      Value="{DynamicResource NormalBorderBrush}" /> 
    <Setter Property="Template" 
      Value="{DynamicResource CheckBoxTemplate}" /> 
    <Setter Property="Foreground" 
      Value="{DynamicResource TextBrush}" /> 
</Style> 
<Style TargetType="{x:Type CheckBox}"> 
    <Setter Property="SnapsToDevicePixels" 
      Value="true" /> 
    <Setter Property="FocusVisualStyle" 
      Value="{DynamicResource CheckBoxFocusVisual}" /> 
    <Setter Property="Background" 
      Value="{DynamicResource NormalBrush}" /> 
    <Setter Property="Foreground" 
      Value="{DynamicResource TextBrush}" /> 
    <Setter Property="BorderBrush" 
      Value="{DynamicResource NormalBorderBrush}" /> 
    <Setter Property="Template" 
      Value="{DynamicResource CheckBoxTemplate}" /> 
</Style> 

<ControlTemplate x:Key="CheckBoxTemplate" 
       TargetType="{x:Type CheckBox}"> 
    <ControlTemplate.Resources> 
    <Storyboard x:Key="HoverOn"> 
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
            Storyboard.TargetName="BackgroundOverlay" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" 
           Value="1" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="HoverOff"> 
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
            Storyboard.TargetName="BackgroundOverlay" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" 
           Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="PressedOn"> 
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
            Storyboard.TargetName="PressedRectangle" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" 
           Value="1" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="PressedOff"> 
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
            Storyboard.TargetName="PressedRectangle" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" 
           Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="CheckedTrue"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CheckIcon" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" 
           Value="1" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="CheckedFalse"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetName="CheckIcon" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" 
           Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="IndeterminateOn"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateIcon" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" 
           Value="1" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="IndeterminateOff"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetName="IndeterminateIcon" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" 
           Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="FocussedOn"> 
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
            Storyboard.TargetName="ContentFocusVisualElement" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" 
           Value="1" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    <Storyboard x:Key="FocussedOff"> 
     <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
            Storyboard.TargetName="ContentFocusVisualElement" 
            Storyboard.TargetProperty="(UIElement.Opacity)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" 
           Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
    </ControlTemplate.Resources> 
    <BulletDecorator Background="Transparent" 
        x:Name="bulletDecorator"> 
    <BulletDecorator.Bullet> 
     <Grid Width="16" 
      Height="16"> 
     <Rectangle Height="14" 
        Margin="1" 
        x:Name="Background" 
        Width="14" 
        Fill="{TemplateBinding Background}" 
        Stroke="{TemplateBinding BorderBrush}" 
        StrokeThickness="{TemplateBinding BorderThickness}" /> 
     <Rectangle Height="14" 
        Margin="1" 
        x:Name="BackgroundOverlay" 
        Width="14" 
        Opacity="0" 
        Fill="{x:Null}" 
        Stroke="{StaticResource HoverBrush}" 
        StrokeThickness="2" /> 
     <Rectangle Height="16" 
        x:Name="PressedRectangle" 
        Width="16" 
        IsHitTestVisible="false" 
        Opacity="0" 
        Stroke="{StaticResource HoverBrush}" 
        StrokeThickness="1" /> 
     <Path Height="10" 
       Margin="1,1,0,1.5" 
       x:Name="CheckIcon" 
       Width="10.5" 
       Opacity="0" 
       Fill="{StaticResource GlyphBrush}" 
       Stretch="Fill" 
       Data="M102.03442,598.79645 L105.22962,597.78918 L106.78825,600.42358 C106.78825,600.42358 108.51028,595.74304 110.21724,593.60419 C112.00967,591.35822 114.89314,591.42316 114.89314,591.42316 C114.89314,591.42316 112.67844,593.42645 111.93174,594.44464 C110.7449,596.06293 107.15683,604.13837 107.15683,604.13837 z" /> 
     <Rectangle Height="8" 
        x:Name="IndeterminateIcon" 
        Width="10" 
        Opacity="0" 
        Fill="{StaticResource GlyphBrush}" /> 
     <Rectangle Height="14" 
        x:Name="DisabledVisualElement" 
        Width="14" 
        Opacity="0" 
        Fill="{StaticResource DisabledBackgroundBrush}" /> 
     <Rectangle Height="16" 
        x:Name="ContentFocusVisualElement" 
        Width="16" 
        IsHitTestVisible="false" 
        Opacity="0" 
        Stroke="{StaticResource HoverShineBrush}" 
        StrokeThickness="1" /> 
     <Rectangle Height="12" 
        x:Name="ShineRectangle" 
        Width="14" 
        IsHitTestVisible="false" 
        Opacity="1" 
        Stroke="{x:Null}" 
        StrokeThickness="1" 
        Fill="{StaticResource ShineBrush}" 
        Margin="2,2,2,2" /> 
     </Grid> 
    </BulletDecorator.Bullet> 
    <ContentPresenter RecognizesAccessKey="True" 
         Margin="5,0,0,0" 
         VerticalAlignment="Top" 
         HorizontalAlignment="Left" /> 
    </BulletDecorator> 
    <ControlTemplate.Triggers> 
    <Trigger Property="IsFocused" 
      Value="True"> 
     <Trigger.ExitActions> 
     <BeginStoryboard Storyboard="{StaticResource FocussedOff}" 
         x:Name="FocussedOff_BeginStoryboard" /> 
     </Trigger.ExitActions> 
     <Trigger.EnterActions> 
     <BeginStoryboard Storyboard="{StaticResource FocussedOn}" 
         x:Name="FocussedOn_BeginStoryboard" /> 
     </Trigger.EnterActions> 
    </Trigger> 
    <MultiTrigger> 
     <MultiTrigger.Conditions> 
     <Condition Property="IsChecked" 
        Value="True" /> 
     <Condition Property="IsThreeState" 
        Value="True" /> 
     </MultiTrigger.Conditions> 
     <MultiTrigger.EnterActions> 
     <BeginStoryboard x:Name="ThreeStateOn_BeginStoryboard" 
         Storyboard="{StaticResource CheckedFalse}" /> 
     </MultiTrigger.EnterActions> 
     <MultiTrigger.ExitActions> 
     <BeginStoryboard x:Name="ThreeStateOff_BeginStoryboard" 
         Storyboard="{StaticResource CheckedTrue}" /> 
     </MultiTrigger.ExitActions> 
    </MultiTrigger> 
    <MultiTrigger> 
     <MultiTrigger.Conditions> 
     <Condition Property="IsChecked" 
        Value="{x:Null}" /> 
     <Condition Property="IsThreeState" 
        Value="True" /> 
     </MultiTrigger.Conditions> 
     <MultiTrigger.EnterActions> 
     <BeginStoryboard x:Name="ThreeStateOn1_BeginStoryboard" 
         Storyboard="{StaticResource IndeterminateOn}" /> 
     </MultiTrigger.EnterActions> 
     <MultiTrigger.ExitActions> 
     <BeginStoryboard x:Name="ThreeStateOff1_BeginStoryboard" 
         Storyboard="{StaticResource IndeterminateOff}" /> 
     </MultiTrigger.ExitActions> 
     <Setter Property="Visibility" 
       TargetName="CheckIcon" 
       Value="Hidden" /> 
    </MultiTrigger> 
    <Trigger Property="IsChecked" 
      Value="True"> 
     <Trigger.ExitActions> 
     <BeginStoryboard Storyboard="{StaticResource CheckedFalse}" 
         x:Name="CheckedTrue_BeginStoryboard" /> 
     </Trigger.ExitActions> 
     <Trigger.EnterActions> 
     <BeginStoryboard x:Name="CheckedTrue_BeginStoryboard1" 
         Storyboard="{StaticResource CheckedTrue}" /> 
     </Trigger.EnterActions> 
    </Trigger> 
    <Trigger Property="IsMouseOver" 
      Value="true"> 
     <Trigger.EnterActions> 
     <BeginStoryboard Storyboard="{StaticResource HoverOn}" /> 
     </Trigger.EnterActions> 
     <Trigger.ExitActions> 
     <BeginStoryboard Storyboard="{StaticResource HoverOff}" /> 
     </Trigger.ExitActions> 
    </Trigger> 
    <Trigger Property="IsEnabled" 
      Value="false"> 
     <Setter Property="Fill" 
       Value="{DynamicResource DisabledBackgroundBrush}" 
       TargetName="Background" /> 
     <Setter Property="Stroke" 
       Value="{DynamicResource DisabledBorderBrush}" 
       TargetName="Background" /> 
     <Setter Property="Foreground" 
       Value="{DynamicResource DisabledForegroundBrush}" /> 
     <Setter Property="Opacity" 
       TargetName="bulletDecorator" 
       Value="0.5" /> 
    </Trigger> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 
+0

嘿,你可以查看源xaml爲您ExpressionDark主題的複選框?如果你可以在你的問題中發表該段? –

+0

請在Question中找到主題ThemeExpressionDark.xaml中的複選框相關XAML代碼。 – Hussain

回答

0

我已刪除以下主題ThemeExpressionDarkXAML代碼解決checboxes的重疊ListViewItem下。 XAMLBorderListViewItem風格:

<Style TargetType="{x:Type ListViewItem}"> 
    <Border SnapsToDevicePixels="true" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" x:Name="border"> 

    <Grid Margin="2,0,2,0"> 
     <Rectangle x:Name="Background" IsHitTestVisible="False" Opacity="0.25" Fill="{StaticResource NormalBrush}" RadiusX="1" RadiusY="1"/> 
     <Rectangle x:Name="HoverRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource NormalBrush}" RadiusX="1" RadiusY="1"/> 
     <Rectangle x:Name="SelectedRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource SelectedBackgroundBrush}" RadiusX="1" RadiusY="1"/> 

     <GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,2,0,2" VerticalAlignment="Stretch" /> 
    </Grid>  
</Style> 

而且應用了一些基本的風格,而不是上面的XAML

1

如果你指的主題是我在過去使用的相同再有,在以下爲CheckBox控件模板看看。請特別注意以下標籤中的SolidColorBrush

<Border.BorderBrush> 
    <SolidColorBrush Color="{DynamicResource BlackColor}" /> 
</Border.BorderBrush> 

在您的主題中的畫筆可能設置爲與您的背景混合的顏色。因爲這會使邊框不可見,所以複選框也將看起來不可見。嘗試將該邊框筆刷設置爲不同的顏色。我將它設置爲BlackColor,它與主題中的所有其他邊框相匹配。

<ControlTemplate x:Key="NuclearCheckBox" TargetType="{x:Type CheckBox}"> 
    <BulletDecorator Background="Transparent" x:Name="bulletDecorator"> 
     <BulletDecorator.Bullet> 
      <Grid Width="13" Height="13"> 
       <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0,0,0,0" Background="{DynamicResource LightBrush}"> 
        <Border.BorderBrush> 
         <SolidColorBrush Color="{DynamicResource BlueBorderColor}" /> 
        </Border.BorderBrush> 
        <Rectangle Visibility="Hidden" Fill="{DynamicResource GlyphBrush}" x:Name="rectangle" Margin="1,1,1,1" /> 
       </Border> 
       <Path Stretch="Fill" Stroke="{DynamicResource GlyphBrush}" StrokeThickness="2" x:Name="path" Width="Auto" Data="M1.0924787,5.372821 L3.1785986,10.519821 10.528543,2.5198207" Margin="1.577,0.134,-0.013,2.866" /> 
      </Grid> 
     </BulletDecorator.Bullet> 
     <ContentPresenter RecognizesAccessKey="True" Margin="5,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" /> 
    </BulletDecorator> 
    <ControlTemplate.Triggers> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 
+0

謝謝你的想法對我有幫助。正如我在答案中所述,完成ListViewItem樣式的更改。 – Hussain