2017-04-07 30 views
2

所以最近我開始使用MahApps.Metro作爲應用程序。 它一直很好,但我無法解決的一個問題是MouseOver對Tile的影響。在Mahapps Tile上更改鼠標懸停效果

我有一個網格,其中有一個擴展器承載所有的Tiles,每個Tiles都代表與特定數據庫的連接。它們綁定到我從另一個數據庫填充的ObservableCollection

<Grid> 
    <Expander Margin="5" Header="Server Connections"> 
     <ListBox ItemsSource="{Binding OmsConnections}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <WrapPanel IsItemsHost="True" /> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <controls:Tile 
         Title="{Binding Name}" 
         controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource BlackBrush}" 
         Background="{DynamicResource GrayBrush2}" 
         Command="{Binding DataContext.TileClickCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" 
         CommandParameter="{Binding}" 
         HorizontalTitleAlignment="Left" 
         Style="{StaticResource LargeTileStyle}" 
         TiltFactor="2"> 
         <Image 
          Width="60" 
          Height="60" 
          Source="{Binding OmsConnectionTypeId, Converter={StaticResource ConnectionTypeToIconConverter}}" /> 
        </controls:Tile> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 
    </Expander> 
</Grid> 

這是通過風格

<Style x:Key="LargeTileStyle" TargetType="controls:Tile"> 
     <Setter Property="Height" Value="125" /> 
     <Setter Property="TitleFontSize" Value="14" /> 
     <Setter Property="TextOptions.TextFormattingMode" Value="Display" /> 
     <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" /> 
     <Setter Property="Width" Value="210" /> 
    </Style> 

應用該樣式所以每當我將鼠標放置到一個項目,我得到了黑色邊框的規定,而這個橙色背景顏色(如果我沒有記錯,是AccentColorBrush3),我不知道如何改變它。

Here's the Image, since my rep is low and i cannot embed it.

而且,我真的,用模板和樣式非常糟糕,所以這是非常有什麼我從網上報廢。任何反饋都將非常讚賞我綁定到集合的方式以及如何更改MouseOver顏色。

回答

1

你可以「覆蓋」的AccentColorBrush3資源通過添加SolidColorBrush資源的ListBox

<ListBox ItemsSource="{Binding OmsConnections}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
    <!-- Specify the highlight brush here: --> 
    <ListBox.Resources> 
     <SolidColorBrush x:Key="AccentColorBrush3" Color="Yellow" /> 
    </ListBox.Resources> 
    <ListBox.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel IsItemsHost="True" /> 
     </ItemsPanelTemplate> 
    </ListBox.ItemsPanel> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <controls:Tile 
         Title="{Binding Name}" 
         controls:ControlsHelper.MouseOverBorderBrush="{DynamicResource BlackBrush}" 
         Background="{DynamicResource GrayBrush2}" 
         Command="{Binding DataContext.TileClickCommand, RelativeSource={RelativeSource AncestorType=ListBox}}" 
         CommandParameter="{Binding}" 
         HorizontalTitleAlignment="Left" 
         Style="{StaticResource LargeTileStyle}" 
         TiltFactor="2"> 
       <Image Width="60" 
         Height="60" 
         Source="{Binding OmsConnectionTypeId, Converter={StaticResource ConnectionTypeToIconConverter}}" /> 
      </controls:Tile> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

非常感謝您的回答! 當然,在週末我放棄了工作,但今天這解決了我的問題。乾杯! – Desomph

+0

不客氣,但請記得接受答案:https://meta.stackexchange.com/questions/23138/how-to-accept-the-answer-on-stack-overflow – mm8

+0

我會忘記它的。 :) 再次感謝。 – Desomph