2011-07-11 37 views
6

誰も、(効果的に)透明/ヒットテストの不可視の背景を持っていますが、項目はまだヒットテストで表示されているWPFリストボックスを実装する方法を提案できますか?選択可能なアイテムを持つ透明なWPFリストボックス

つまり、ListBoxの背景をクリックしてその下のコントロールにすることができますが、それでもListBoxのアイテムを選択できるようにしたいと思います。

カスタムレイアウトパネル(ListBoxはアイテムを選択する必要があるため)を使用しています。しかし、私はこのパネルを他のコントロールの上にオーバーレイする必要があり、それらをそのまま使用することができます。

私はBackground="Transparent"IsHitTestVisible="False"の様々な組み合わせを試してみたが、私は私が間違っている行にあるかもしれない疑い...

希望これは理にかなって - 私はWPFに新しいですので、任意のガイダンスが最も理解されるであろう!ありがとう。

答えて

7

は「{X:ヌル}背景設定してみてください。ListeItemContainerとListBoxコントロール自体には

透明あなたはまだそれにヒットテストを取得している理由である、まだヒットテスト可能である

EDIT

私はサンプルの上にWPFインスペクタを実行し、デフォルトのリストボックスのテンプレート内ScrollViewerのは、マウスクリックがリストボックスに滞在させたことがわかった。

ここにありますScrollViewerを含まないListBoxコントロールテンプレート。リストボックスの背後にあるTextBoxにマウスを通過させることはできますが、ユーザーはリストボックス内の項目を選択することができます。

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    > 
    <Window.Resources> 
     <SolidColorBrush x:Key="ListBorder" Color="#828790"/> 
     <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}"> 
      <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> 
      <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/> 
      <Setter Property="BorderThickness" Value="1"/> 
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
      <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> 
      <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"> 
          <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
         </Border> 
         <ControlTemplate.Triggers> 
          <Trigger Property="IsEnabled" Value="false"> 
           <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
          </Trigger> 
          <Trigger Property="IsGrouping" Value="true"> 
           <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> 
          </Trigger> 
         </ControlTemplate.Triggers> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Window.Resources> 
    <Grid Width="100"> 
    <TextBox TextWrapping="Wrap">I'm in the background. I'm in the background. I'm in the backgroun.</TextBox> 
    <ListBox Background="{x:Null}" Style="{StaticResource ListBoxStyle1}"> 
     <ListBoxItem Margin="10" Background="#999">Hello</ListBoxItem> 
     <ListBoxItem Margin="10" Background="#999">Hello</ListBoxItem> 
     <ListBoxItem Margin="10" Background="#999">Hello</ListBoxItem> 
     <ListBoxItem Margin="10" Background="#999">Hello</ListBoxItem> 
    </ListBox> 
    </Grid> 
</Window> 
+0

ありがとうございました。@ Nathan - 試しましたが、うまくいきません。 'IsHitTestVisible =" False "を設定しない限り、下にあるものはクリック可能ではありませんが、もちろんアイテムが選択できないことを意味します... – FuzzyLogic

+0

Christian MoserのWPF Inspector(http://www.wpftutorial.net/inspector .html)を使用して、どのレイヤー/コントロールがListBoxによってレンダリングされているかを確認します。これは、ヌルの背景を持つ必要があるレイヤーを見つけるのに役立ちます。 – NathanAW

+0

私はこれをWPF Inspectorで調べ、ListBox内のScrollViewerが問題であることを発見しました。上記は、ListBoxテンプレートからScrollViewerを削除するサンプルです。あなたが尋ねたとおりに動作するようです。 – NathanAW

関連する問題