ListView背景颜色不起作用

时间:2016-01-30 16:57:20

标签: c# wpf listview background

我有一个简单的listView放在其他元素中。 由于我想模拟探索者的风格,我已经做到了:

<ListView x:Name="lvAllowedPPtab2" Grid.Row="1" FontSize="12" Background="{x:Null}"  BorderBrush="Gainsboro" BorderThickness="5" Margin="10" VerticalAlignment="Stretch" >
              <ListView.ItemsPanel >
                <ItemsPanelTemplate >
                  <WrapPanel Orientation="Horizontal" Width="250" Background="{x:Null}"  VerticalAlignment="Top"></WrapPanel>
                </ItemsPanelTemplate>
              </ListView.ItemsPanel>
            </ListView>

问题在于,通过这样做,背景变为彩色,而我希望它是透明的= null。

you can get it here

通过查看

  

enter image description here

作为一种解决方法,我搜索了类似的东西,但没有发现任何类似的事件。

不知道发布我的完整xaml是否有帮助 谢谢你的帮助

- ADD-- 根据要求,我发布了我的xaml的更广泛部分:

 <TabItem Name="tabItem2" HorizontalAlignment="Center" Height="80" MouseLeftButtonUp="TabItem_MouseLeftButtonUp"  FontSize="{StaticResource TOOLTIP_FONTSIZE}" IsSelected="false" >
    <TabItem.Header>
      <StackPanel>
        <TextBlock Text="&#xF0F7;" FontSize="{StaticResource TAB_FONTSIZE}"/>
        <TextBlock Name="tbTab2" Visibility="Hidden" FontSize="{StaticResource BUTTON_FONTSIZE}" />
      </StackPanel>
    </TabItem.Header>
    <TabItem.Background>
      <ImageBrush/>
    </TabItem.Background>
    <Grid >
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      <Border x:Name="Border1Tab2" BorderBrush="Gainsboro" BorderThickness="5" Width="200" Margin="10,10,10,10" >
        <StackPanel Margin="-1.8,-0.8,2.2,1.4">
          <ListBox x:Name="lbxPalletsTab2" Background="{x:Null}" BorderBrush="{x:Null}" Height="600" SelectionChanged="ListBox_SelectionChanged" Margin="12,10.2,8.4,10.4" />
        </StackPanel>
      </Border>
      <Border x:Name="Border2Tab2" BorderBrush="Gainsboro" MinWidth="150" BorderThickness="5" Grid.Column="1" Margin="10,10,10,10">
        <Grid >
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300px"/>
            <ColumnDefinition Width="*"/>
          </Grid.ColumnDefinitions>

          <Grid  HorizontalAlignment="Stretch" Grid.Column="0">
            <Grid.RowDefinitions>
              <RowDefinition Height="50px"/>
              <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <TextBlock Name="tbkPPtab2" Grid.Row="0" FontSize="22" Background="{x:Null}" FontWeight="Black" Text="---" HorizontalAlignment="Center" VerticalAlignment="Bottom"></TextBlock>
            <ListView x:Name="lvAllowedPPtab2" Grid.Row="1" FontSize="12" Background="{x:Null}"  BorderBrush="Gainsboro" BorderThickness="5" Margin="10" VerticalAlignment="Stretch" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown">
              <ListView.ItemsPanel >
                <ItemsPanelTemplate >
                  <WrapPanel Orientation="Horizontal" Width="250" Background="{x:Null}"  VerticalAlignment="Top"></WrapPanel>
                </ItemsPanelTemplate>
              </ListView.ItemsPanel>
            </ListView>

          </Grid>
          <Border  Grid.Column="1" BorderBrush="Gainsboro"  BorderThickness="5" Margin="10,60,10,10">
            <Grid Name="grdPalletTab2" AllowDrop="True" Drop="Grid_Drop"/>
          </Border>
        </Grid>
      </Border>
    </Grid>
  </TabItem>

- ADD-- 在我的xaml中到处都出现同样的问题。即使只添加一个透明或空背景的空列表视图也会使它成为深蓝色。我想我无法覆盖我的风格winwdow的预设。

- ADD2 ---正如Sivasubramanian所说,这是我样式表的相关部分

<Style TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="{DynamicResource BackgroundDepth4}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BackgroundDepth4}"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Foreground" Value="{DynamicResource TextDepth1}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type ListBox}">
      <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
        <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="{x:Null}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
          <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
        </ScrollViewer>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="IsEnabled" Value="false">
          <Setter Property="Opacity" TargetName="Bd" Value="{DynamicResource DisabledOpacity}"/>
        </Trigger>

      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
</Setter>

<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type ListBoxItem}">
      <Grid x:Name="Bd" Background="{TemplateBinding Background}" Height="Auto" SnapsToDevicePixels="true">
        <VisualStateManager.VisualStateGroups>
          <VisualStateGroup x:Name="CommonStates">
            <VisualStateGroup.Transitions>
              <VisualTransition GeneratedDuration="0:0:0.2">
                <VisualTransition.GeneratedEasingFunction>
                  <CubicEase EasingMode="EaseOut"/>
                </VisualTransition.GeneratedEasingFunction>
              </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="Normal"/>
            <VisualState x:Name="MouseOver">
              <Storyboard>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="MouseOverElement">
                  <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="Disabled">
              <Storyboard>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Bd">
                  <EasingDoubleKeyFrame KeyTime="0" Value="{StaticResource DisabledOpacity}"/>
                </DoubleAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
          </VisualStateGroup>
          <VisualStateGroup x:Name="SelectionStates">
            <VisualState x:Name="Unselected"/>
            <VisualState x:Name="Selected">
              <Storyboard>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="SelectedElement">
                  <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                </DoubleAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
            <VisualState x:Name="SelectedUnfocused">
              <Storyboard>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="SelectedElement">
                  <EasingDoubleKeyFrame KeyTime="0" Value="0.5"/>
                </DoubleAnimationUsingKeyFrames>
              </Storyboard>
            </VisualState>
          </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Rectangle x:Name="SelectedElement" Fill="{DynamicResource CannoliAccentColorBrush}" HorizontalAlignment="Stretch" Height="Auto" Stroke="{x:Null}" VerticalAlignment="Stretch" Width="Auto" StrokeThickness="0" Opacity="0"/>
        <Rectangle x:Name="MouseOverElement" Fill="{x:Null}" HorizontalAlignment="Stretch" Height="Auto" Stroke="{DynamicResource CannoliAccentColorBrush}" VerticalAlignment="Stretch" Width="Auto" StrokeThickness="2" Opacity="0"/>
        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}"/>
      </Grid>
      <ControlTemplate.Triggers>
        <Trigger Property="Selector.IsSelected" Value="True">
          <Setter Property="Foreground" Value="{DynamicResource WindowTitleForegroundColorBrush}"/>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
</Setter>

0 个答案:

没有答案