2010-12-10 4 views
2

나는 ListBox를 가지고있다. 흰색 배경입니다. 어떻게 제거 할 수 있습니까?Silverlight : 목록 상자의 배경을 투명하게 만드시겠습니까?

여기 제가 시도하는 XAML입니다. 내가 무엇을하더라도, 나는 그 배경을 없앨 수 없다. (나는 그것이 ListBox의 모든 공간을 차지하는 일이 각 항목에, 또는 경우에 확실하지 않다가 ListBox 자체의 배경에 있다면.) 나는 실버 라이트 4 사용하고

<ListBox x:Name="topThreeHits" ItemsSource="{Binding TopThreeHits}" Margin="0,10,0,0"> 
       <ListBox.ItemContainerStyle> 
        <Style TargetType="ListBoxItem"> 
         <Setter Property="Background" Value="Transparent" /> 
        </Style> 
       </ListBox.ItemContainerStyle> 
       <ListBox.ItemsPanel> 
        <ItemsPanelTemplate> 
         <StackPanel Orientation="Horizontal" Background="Transparent"/> 
        </ItemsPanelTemplate> 
       </ListBox.ItemsPanel> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Margin="10,0" Background="Transparent"> 
          <Image Source="{Binding Image, FallbackValue=/PlumPudding;component/Images/file.png}" /> 
          <TextBlock> 
          <Run Text="{Binding Name, FallbackValue='File Name'}" FontWeight="Bold" /> 
          <Run Text="." Foreground="#787878" FontWeight="Light" /> 
          <Run Text="{Binding TypeExtension, FallbackValue='type'}" Foreground="#787878" FontWeight="Light" /> 
          </TextBlock> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

.

답변

1

ListBox 주위에 녹색 배경이있는 테두리를 추가하고 ListBox에 대해 배경을 투명하게 설정하려고했는데 제대로 작동하는 것 같습니다.

<Border Background="Green"> 
    <ListBox x:Name="topThreeHits" 
      Background="Transparent" 
      ItemsSource="{Binding Customers}" Margin="0,10,0,0"> 
     <ListBox.ItemContainerStyle> 
      <Style TargetType="ListBoxItem"> 
       <Setter Property="Background" Value="Transparent" /> 
      </Style> 
     </ListBox.ItemContainerStyle> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal" Background="Transparent"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Margin="10,0" Background="Transparent"> 
        <Image Source="{Binding Image, FallbackValue=/PlumPudding;component/Images/file.png}" /> 
        <TextBlock> 
        <Run Text="{Binding Name, FallbackValue='File Name'}" FontWeight="Bold" /> 
        <Run Text="." Foreground="#787878" FontWeight="Light" /> 
        <Run Text="{Binding TypeExtension, FallbackValue='type'}" Foreground="#787878" FontWeight="Light" /> 
        </TextBlock> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</Border> 
3

코드가 올바르게 작동하고 배경 스타일을 올바르게 설정하고 있습니다. 나는 등, 당신이 롤오버를 포함하여 어떤 배경도 없다, 그래서 완전히 기본 항목 컨테이너를 날려되어 수행 할 작업을 가정하고

그렇게 할 수있는 가장 좋은 방법은 다음과 같이이다 :

 <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
     <Setter Property="Template" > 
      <Setter.Value> 
      <ControlTemplate TargetType="ListBoxItem"> 
       <ContentPresenter Content="{TemplateBinding Content}" /> 
      </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
     </Style> 
    </ListBox.ItemContainerStyle> 
+0

사실 내가 원하는 것은 배경을 제거하는 것입니다. 롤오버를 유지하고 싶었습니다. 위 코드에 게시 한 코드를 추가했는데 이제 데이터 바인딩이 작동하지 않습니다. 기본 폴백 값으로 채워집니다. 왜 그런지 모르겠습니다. –

+1

좋아요, 이것은 제가 listboxitem의 모든 속성을 retemplating하지 않고 정확히하고 싶은 일입니다. 훨씬 더 간단합니다. –

관련 문제