2017-04-16 6 views
0

私はリストビューを持っていて、パディングは2でなければならず、カラーはシステムテーマ(Windows 8.1を使用)を取得する必要がありますが、非常に醜いです。WPF ListView IsSelectedボーダーの不透明度を設定する

<ListView.Resources> 
<Style TargetType="ListViewItem"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListViewItem"> 
       <Border Name="Border" Padding="2" SnapsToDevicePixels="True"> 
        <ContentPresenter /> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsSelected" Value="true"> 
         <Setter TargetName="Border" Property="Background" Value="{x:Static SystemParameters.WindowGlassBrush}"/> 
        </Trigger> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Setter Property="IsSelected" Value="true"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
</ListView.Resources> 

TIP:私のDataTemplateでCornerRadius = 10を使用します。

<DataTemplate x:Key="DT"> 
<StackPanel Orientation="Vertical"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="50*"/> 
      <RowDefinition Height="50*"/> 
     </Grid.RowDefinitions> 

     <Border Background="{Binding HEXRengi}" MinHeight="100" MinWidth="150" Height="100" Width="150" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.RowSpan="2" CornerRadius="10"/> 


     <ToggleButton x:Name="HEXRenkAl" Style="{DynamicResource DüzRenkPaletiDüğmeBiçimi}" Grid.Row="0" Click="HEXRenkAl_Click"> 
      <Border Background="{Binding HEXRengi}" MinHeight="50" MinWidth="150" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="10"> 
       <TextBox Text="{Binding HEXRengi}" Style="{DynamicResource SeçilebilirAmaYazılamazMetinKutusu}" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Justify" TextWrapping="Wrap" Foreground="White" FontFamily="Century Gothic" FontSize="16" FontWeight="Bold"/> 
      </Border> 
     </ToggleButton> 

     <ToggleButton x:Name="RGBRengiAl" Style="{DynamicResource DüzRenkPaletiDüğmeBiçimi}" Grid.Row="1" Click="RGBRengiAl_Click"> 
      <Border Background="{Binding HEXRengi}" MinHeight="50" MinWidth="150" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="05"> 
       <TextBox Text="{Binding RGBRengi}" Style="{DynamicResource SeçilebilirAmaYazılamazMetinKutusu}" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Justify" TextWrapping="Wrap" Foreground="White" FontFamily="Century Gothic" FontSize="16" FontWeight="Bold"/> 
      </Border> 
     </ToggleButton> 

    </Grid> 
</StackPanel> 
</DataTemplate> 

このようになります。

enter image description here

とIsSelected。私はsetterプロパティの不透明度の値を使用

enter image description here

は、すべての項目を適用します。 ボーダーにのみ適用してください。の全商品ではありません。

<Trigger Property="IsSelected" Value="true"> 
<Setter TargetName="Border" Property="Background" Value="{x:Static SystemParameters.WindowGlassBrush}"/> 
<Setter TargetName="Border" Property="Opacity" Value=".5"/> 
</Trigger> 

enter image description here

私はそれをどのように行うことができますか?アドバイスをありがとう。

答えて

0

私はセッタープロパティの不透明度値を使用すると、すべてのアイテムを適用します。国境にのみ適用されるべきであり、すべてのアイテムではありません。

不透明度の値は、すべての項目に適用され、なぜあなたは不思議に思っている場合は、「ボーダー」と命名していると、あなたのTriggerで名前をターゲットとしているので、それはです。

<Border Name="Border" Padding="2" SnapsToDevicePixels="True"> 
    <ContentPresenter /> 
</Border> 
+0

私は知っているが、ちょうどエッジに適用する方法を知りたいです。 –

+0

ご迷惑をおかけして申し訳ございません。ターゲットとする "_edge_"に名前をつけ、トリガでこれをターゲットにする必要があります。また、Blendを試してみると、遊びやすいかもしれません。 – Bubba

+0

ありがとう、私は働いています。 –

関連する問題