2013-10-02 2 views
0

마우스가 목록 상자의 항목 위에있을 때 파란 상자를 제거하려고 시도했지만 생각이 다 찼을 때 아마도 아무 것도 나오지 않을 것입니다. 미리 감사드립니다. enter image description hereListBoxItem의 파란색 테두리를 제거 할 때 MouseOver

간단한 목록 상자

<ListBox ItemsSource="{Binding Mylist}" /> 

불행하게도, 솔루션은 아래

<ListBox ItemsSource="{Binding lista}" > 
     <ListBox.ItemContainerStyle> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Style.Resources> 
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/> 
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/> 
       </Style.Resources> 
      </Style> 
     </ListBox.ItemContainerStyle> 

    </ListBox> 

enter image description here

답변

1

이이 동작은 컨트롤 템플릿에 의해 결정됩니다 작동하지 않습니다.

XAML에 익숙한 경우 ListBox를 마우스 오른쪽 단추로 클릭하고 Edit Template -> Edit Copy...으로 이동하여 Border 태그를 확인하십시오. 당신을 도울뿐만 아니라,이 링크를 확인하기 위해

: ListBox Styles and Templates

+0

답변을보다 정확하게 작성하십시오. – Maximus

+0

Chris W 응답 완료. – Tico

0

새로운 문제가 나와서, 나는 파란색 테두리

<Style TargetType="ListBoxItem"> 
     <Setter Property="HorizontalContentAlignment" Value="Left" /> 
     <Setter Property="VerticalContentAlignment" Value="Top" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ListBoxItem"> 
        <Grid Background="{TemplateBinding Background}"> 
         <ContentPresenter 
          x:Name="contentPresenter" 
          Content="{TemplateBinding Content}" 
          ContentTemplate="{TemplateBinding ContentTemplate}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          Margin="{TemplateBinding Padding}"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

없이 목록 상자를 획득하지만이

<Style TargetType="ListBoxItem" x:Key="ContainerStyle"> 
     <Setter Property="ContentTemplate" Value="{StaticResource not_mouseover}"/> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="ContentTemplate" Value="{StaticResource mouseover}"/> 
      </Trigger> 

     </Style.Triggers> 
    </Style> 
    <ListBox ItemsSource="{Binding lista}" ItemContainerStyle="{StaticResource ContainerStyle}"> 
처럼 ItemContainerStyle 설정

이 경우에는 작동하지 않는다는 것을 알 수 있습니다 (이전과 같이 파란색 테두리가 나타남). ItemTemplate을 지정된 DateTemplate으로 설정하면 제대로 작동하지만 여기서는 그렇지 않습니다. 왜 그런지 아십니까? 나는 이것을 분류했다. 그냥 하나 개의 ListBoxItem의

<Style x:Key="item_template" TargetType="ListBoxItem"> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Template" Value="{StaticResource control_mouseover}"/> 
      </Trigger> 
      <Trigger Property="IsMouseOver" Value="False"> 
       <Setter Property="Template" Value="{StaticResource control_not_mouseover}"/> 
      </Trigger> 
     </Style.Triggers>   
    </Style> 
</Window.Resources> 
    <ListBox ItemsSource="{Binding lista}" ItemContainerStyle="{StaticResource item_template}"> 
    </ListBox> 

에 대한 스타일과 아마 누군가가이 활용됩니다 블루 국경

<ControlTemplate x:Key="control_not_mouseover" TargetType="ListBoxItem"> 
     <ContentPresenter 
          Content="{TemplateBinding Content}" 
          ContentTemplate="{StaticResource not_mouseover}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          Margin="{TemplateBinding Padding}"/> 
    </ControlTemplate> 
    <ControlTemplate x:Key="control_mouseover" TargetType="ListBoxItem"> 
      <ContentPresenter 
          Content="{TemplateBinding Content}" 
          ContentTemplate="{StaticResource mouseover}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
          Margin="{TemplateBinding Padding}"/> 
     </ControlTemplate> 

을 제거하기 위해 ControlTemplate이를 선언했다.

0

x:Key이없는 스타일은 모든 TargetType 컨트롤에서 작동합니다. 예를 들어
:

<Style TargetType="Button"> 
     <Setter Property="Background" Value="Green" /> 
</Style> 

가 새 Button 제어를 설정마다 작동합니다. 따라서 <Button/>과 같은 스타일을 지정하지 않고 Button을 삽입하면 위에 지정된대로 녹색 배경을 갖게됩니다. 한편

:

<Style TargetType="Button" x:Key="myButton"> 
     <Setter Property="Background" Value="Green" /> 
</Style> 

Style 템플릿을 지정 Button 컨트롤에 대해 작동합니다.
예 : <Button Style="{StaticResource myButton}" /> ->이 Button은 녹색 배경을 가지며 다른 모든 버튼은 기본 배경색을 갖습니다.

내 충고는 : 나중에 설정할 수 있도록 항상 x : Key를 스타일에 설정하십시오. 시나리오에서는 을 첫 번째 코드에 넣고 나중에 선언 된 스타일을 제거하십시오. 그것은 작동해야합니다.

+0

솔루션이 포함 된 이전 메시지를 업데이트했습니다. 노력과 희생 된 시간을 가져 주셔서 감사합니다. – Maximus

+0

내 대답이 유용 했습니까? 그렇다면 대답으로 설정할 수 있습니까? 감사합니다. – Tico

관련 문제