2008-12-23 11 views
8

ListBox'ımdaki okları kaydırıp görüntüleri w/text, vb. Bir öğeyi tıklattığımda, onu seçmek için, bir web tarayıcısını açmak ve belirli bir URL'ye gitmek için bir işlem çalıştırır. Şimdi sahip olduğum problem, WPF uygulaması odağı kaybettiğinde ve web tarayıcısı açıldığında, liste kutusunun içine tıklanan öğenin beyaza dönüşmesidir. İşte bütün ListBox XAML. Seçilen öğeleri şeffaf olarak ayarladım, bu da WPF uygulamasının odağı kaybetmesiyle bir ilgisi var mı?WPF ListBox Image Seçilmiş olan destan devam ediyor

WPF uygulamasına geri odağı ayarlamak için web tarayıcısını açmak için işlemi çalıştıran kodu ekleyebileceğim bir şey var mı?

Teşekkürler.

<ListBox ItemsSource="{Binding Source={StaticResource WPFApparelCollection}}" Margin="61,-8,68,-18" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden" SelectionMode="Single" x:Name="list1" MouseLeave="List1_MouseLeave" MouseMove="List1_MouseMove" Style="{DynamicResource ListBoxStyle1}" Background="Transparent" BorderThickness="0"> 
     <ListBox.ItemContainerStyle> 
      <Style TargetType="{x:Type ListBoxItem}"> 
       <Setter Property="Background" Value="Transparent" /> 
       <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" /> 
       <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" /> 
       <Setter Property="Padding" Value="20,10,20,10" /> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
          <Border x:Name="Bd" SnapsToDevicePixels="true" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"> 
           <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
          </Border> 
          <ControlTemplate.Triggers> 
           <Trigger Property="IsSelected" Value="true"> 
            <Setter Property="Background" TargetName="Bd" Value="Transparent" /> 
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" /> 
           </Trigger> 
           <MultiTrigger> 
            <MultiTrigger.Conditions> 
             <Condition Property="IsSelected" Value="true" /> 
             <Condition Property="Selector.IsSelectionActive" Value="false" /> 
            </MultiTrigger.Conditions> 
            <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" /> 
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /> 
           </MultiTrigger> 
           <Trigger Property="IsEnabled" Value="false"> 
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> 
           </Trigger> 
          </ControlTemplate.Triggers> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </ListBox.ItemContainerStyle> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" /> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Orientation="Vertical"> 
        <Grid> 
         <Image Source="{Binding Image}" MouseLeave="Image_MouseLeave" MouseEnter="Image_MouseEnter" Cursor="Hand" Tag="{Binding Link}" MouseLeftButtonDown="Image_MouseLeftButtonDown" VerticalAlignment="Top" HorizontalAlignment="Left"></Image> 
        </Grid> 
        <Label Content="{Binding Name}" Cursor="Hand" Tag="{Binding Link}" MouseLeftButtonDown="Label_MouseLeftButtonDown" VerticalAlignment="Bottom" Foreground="White" Style="{StaticResource Gotham-Medium}" FontSize="8pt" HorizontalAlignment="Center" /> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 

cevap

36

Bir ListBox'ta seçim renkleriyle oynatılırken karşılaştığım bir numara, bunlarla savaşmak yerine sistem fırçalarıyla çalışmaktır.

ListBox odaklandığında ve bir öğe seçildiğinde, bu öğenin arka planı SystemColors.HighlightBrush'tır. Ancak, ListBox odağı kaybettiğinde, seçilen öğenin arka planı SystemColors.ControlBrush olur.

Bunu bilerek, bu liste için sistem fırçalarını, ListBox geçersiz kılabilirsiniz, böylece içindeki öğeler istediğiniz renklerle boyanır.

<ListBox> 
    <ListBox.Resources> 
     <!-- override the system brushes so that selected items are transparent 
      whether the ListBox has focus or not --> 
     <SolidColorBrush 
      x:Key="{x:Static SystemColors.HighlightBrushKey}" 
      Color="Transparent" /> 
     <SolidColorBrush 
      x:Key="{x:Static SystemColors.ControlBrushKey}" 
      Color="Transparent" /> 
     <SolidColorBrush 
      x:Key="{x:Static SystemColors.HighlightTextBrushKey}" 
      Color="Black" /> 
    </ListBox.Resources> 
    <!-- ... your items here ... --> 
</ListBox> 
+0

Wow ... siz erkeksiniz. Burada çok güzel bir fikir. Webform/Winform'u değil, WPFish'i düşünmeye başladım. Tekrar teşekkürler. John –

+0

Ancak, ListBox'unuzda bir içerik menünüz varsa, ContextMenu öğesindeki öğeler vurgulanmayacaktır, değil mi? Her iki davranışa nasıl ulaşabilirim? – jpsstavares

+0

@jpsstavares Evet, ContextMenus teknik olarak kendi sahipleriyle aynı görsel ağacın bir parçası değildir, bu yüzden fırçalar kalıtılmaz. Denemediğim halde, onları ContextMenu'nun kaynaklarında çoğaltmanız gerekebilir. –

İlgili konular