2016-09-26 5 views
1

MahAppsMetro을 사용 중이므로 ResourceDictionary을 사용하여 디자인 색상을 변경할 수 있습니다. 이제 색상을 파란색으로 변경했습니다. 그러나 combobox/tableselected itemtextcolor을 변경하는 방법을 모르겠습니다. 그래서ResourceDictionary의 Mouseover에서 Combobox/Table Item textcolor를 변경하십시오.

Example: Combobox

Example: Table

을 지금은 있습니다 .. ResourceDictionary에 의해 흰색으로 텍스트 색상을 변경하려면 그것은 아직이 같은 : : 은 이제 다음과 같습니다

<!-- re-set brushes too --> 
<SolidColorBrush x:Key="HighlightBrush" Color="{StaticResource HighlightColor}" options:Freeze="True" /> 
<SolidColorBrush x:Key="AccentColorBrush" Color="{StaticResource AccentColor}" options:Freeze="True" /> 
<SolidColorBrush x:Key="AccentColorBrush2" Color="{StaticResource AccentColor2}" options:Freeze="True" /> 
<SolidColorBrush x:Key="AccentColorBrush3" Color="{StaticResource AccentColor3}" options:Freeze="True" /> 
<SolidColorBrush x:Key="AccentColorBrush4" Color="{StaticResource AccentColor4}" options:Freeze="True" /> 

<SolidColorBrush x:Key="WindowTitleColorBrush" Color="{StaticResource AccentColor}" options:Freeze="True" /> 

<LinearGradientBrush x:Key="ProgressBrush" EndPoint="0.001,0.5" StartPoint="1.002,0.5" options:Freeze="True"> 
    <GradientStop Color="{StaticResource HighlightColor}" Offset="0" /> 
    <GradientStop Color="{StaticResource AccentColor3}" Offset="1" /> 
</LinearGradientBrush> 

<SolidColorBrush x:Key="CheckmarkFill" Color="{StaticResource AccentColor}" options:Freeze="True" /> 
<SolidColorBrush x:Key="RightArrowFill" Color="{StaticResource AccentColor}" options:Freeze="True" /> 

항목의 MouseOver에 흰색 텍스트를 사용하려면 ResourceDictionary에 추가해야 할 내용을 알려주십시오.

내가 원하는 것을 분명히 알기를 바랍니다. 다른 정보가 필요하면 알려주세요.

편집 : Combobox를 들어

가 지금 노력하고 있습니다. 하지만 DataGrid에는 해당되지 않습니다. 여기 내가 DataGrid을 추가하는 방법입니다

<DataGrid x:Name="mydatagrid" SelectionUnit="FullRow" HorizontalAlignment="Left" Margin="159,33,0,0" VerticalAlignment="Top" Height="204" Width="275" Background="{x:Null}" BorderBrush="Transparent" CanUserAddRows="False" GridLinesVisibility="None" BorderThickness="0" CanUserResizeRows="False"> 
        <DataGrid.Columns> 
         <DataGridTextColumn Header="User" Binding="{Binding User, Mode=OneWay}" Width="100" IsReadOnly="True" CanUserResize="False" /> 
         <DataGridTextColumn Header="Vote" Binding="{Binding Vote, Mode=OneWay}" Width="90" IsReadOnly="True" CanUserResize="False" /> 
         <DataGridTemplateColumn Header="Status" Width="66" IsReadOnly="True" CanUserResize="False"> 
          <DataGridTemplateColumn.CellTemplate> 
           <DataTemplate> 
            <Image Source="{Binding Status, Mode=OneWay}" Width="16"/> 
           </DataTemplate> 
          </DataGridTemplateColumn.CellTemplate> 
         </DataGridTemplateColumn> 
         <DataGridTextColumn Header="Real_Username" Binding="{Binding Real_Username, Mode=OneWay}" Width="90" IsReadOnly="True" CanUserResize="False"/> 
        </DataGrid.Columns> 
       </DataGrid> 

내가 내 Application.xaml에 다른 방법을 추가하는 시도와 함께 IsMouseOver의 트리거를 확장 : 내가 잘못 뭐하는 거지

<Setter Property="Controls.Foreground" Value="{DynamicResource AccentSelectedColorBrush}" /> 

?

+0

나는 그것을 직접 시도한 적이 없지만 트리거를 보는 것이 좋습니다 : http://www.wpf-tutorial.com/styles/trigger-datatrigger-event-trigger/ – MikeT

답변

0

가능하지만 MouseOver의 경우 MahApps ComboBoxItem을 재정의하고 트리거로 확장해야합니다. SelectedItem은 ColorBrush : AccentSelectedColorBrush를 사용합니다. 여기에 MouseOver에 대한 트리거로 확장 원래 MetroComboBoxItem입니다

app.xaml가 쉽게 데이터 그리드를 들어

<Application x:Class="WpfApplication.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
<ResourceDictionary> 
    <ResourceDictionary.MergedDictionaries> 
    <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! --> 
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" /> 
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" /> 
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" /> 
    <!-- Accent and AppTheme setting --> 
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> 
    <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 
    </ResourceDictionary.MergedDictionaries> 

    <SolidColorBrush x:Key="AccentSelectedColorBrush" Color="DeepPink" /> 
    <Style TargetType="ComboBoxItem" x:Key="MetroComboBoxItem"> 
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" /> 
    <Setter Property="Padding" Value="2" /> 
    <Setter Property="HorizontalContentAlignment" Value="Left" /> 
    <Setter Property="VerticalContentAlignment" Value="Top" /> 
    <Setter Property="Background" Value="{DynamicResource TransparentWhiteBrush}" /> 
    <Setter Property="BorderThickness" Value="1" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ComboBoxItem"> 
       <Grid Background="{TemplateBinding Background}" Margin="0,0.5"> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal" /> 
          <VisualState x:Name="MouseOver"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" 
                    Storyboard.TargetName="MouseOverRectangle"> 
             <EasingDoubleKeyFrame KeyTime="0:0:0.1" 
                   Value=".65" /> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
          <VisualState x:Name="Disabled"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" 
                    Storyboard.TargetName="contentPresenter"> 
             <SplineDoubleKeyFrame KeyTime="0" 
                   Value=".55" /> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="SelectionStates"> 
          <VisualState x:Name="Unselected" /> 
          <VisualState x:Name="Selected"> 
           <Storyboard> 
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" 
                    Storyboard.TargetName="SelectedRectangle"> 
             <EasingDoubleKeyFrame KeyTime="0:0:0.1" 
                   Value="1" /> 
            </DoubleAnimationUsingKeyFrames> 
           </Storyboard> 
          </VisualState> 
         </VisualStateGroup> 
         <VisualStateGroup x:Name="FocusStates"> 
          <VisualState x:Name="Focused"> 
           <Storyboard /> 
          </VisualState> 
          <VisualState x:Name="Unfocused" /> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        <Rectangle x:Name="SelectedRectangle" 
           IsHitTestVisible="False" 
           Opacity="0" 
           Fill="{DynamicResource AccentColorBrush}" /> 
        <Rectangle x:Name="MouseOverRectangle" 
           IsHitTestVisible="False" 
           Opacity="0" 
           Fill="{DynamicResource AccentColorBrush3}" /> 
        <ContentControl Foreground="{TemplateBinding Foreground}"> 
         <ContentPresenter x:Name="contentPresenter" 
              Margin="{TemplateBinding Padding}" 
              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" /> 
        </ContentControl> 
        <Rectangle x:Name="FocusVisualElement" 
           Stroke="{DynamicResource HighlightBrush}" 
           StrokeThickness="1" 
           Visibility="Collapsed" /> 
       </Grid> 

       <ControlTemplate.Triggers> 
        <Trigger Property="IsSelected" Value="True"> 
         <Setter Property="Foreground" Value="{DynamicResource AccentSelectedColorBrush}" /> 
        </Trigger> 
        <!-- This Trigger is new --> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Setter Property="Foreground" Value="{DynamicResource AccentSelectedColorBrush}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
     </Setter> 
    </Style> 
    </ResourceDictionary> 
    </Application.Resources> 
</Application> 
+0

답변 해 주셔서 감사합니다. 방금 제공 한 코드의 일부를 검색하여 ILSpy를 사용하여 DLL을 열었습니다. 그래서 나는 변화를 어디에서해야하는지 알게되었다고 생각합니다. 불행히도 나는 그것을 바꿀 수있는 방법을 모르고있다. ILSpy를 통해 나는 그것을 읽을 수만있다. .dll 파일에서이 부분을 변경하는 방법을 설명 할 수 있습니까? 아니면 내가하고 싶은 일이 잘못 되었습니까? –

+0

왜 코드 스 니펫을 Window.Resources에 추가하지 않으시겠습니까? 그 다음 그것은 끝난다. DLL을 변경하는 것은 필요하지 않습니다. 두 번째 옵션은 소스를 변경하는 것입니다 (GitHub https://github.com/MahApps/MahApps.Metro의 MahApps에서 소스를 다운로드하고 Controls.ComboBox.xaml을 직접 변경하십시오 (트리거와 함께 스타일을 추가 할 수 있음). 자신의 MahApps.dll – WPFGermany

+0

나는 하나 이상의 창을 가지고 있으며 여러 콤보 상자를 사용합니다. 따라서 모든 콤보 박스에 대해 한 지점에서만 변경하고 싶습니다. 두 번째 옵션을 선호하는 이유는 무엇입니까? 이미 소스를 다운로드하여 Visual Studio에서 열고 변경 사항을 추가 할 적절한 위치를 찾았습니다. "이름"TextBoxHelper "가 네임 스페이스"clr-namespace : MahApps.Metro.Controls "에 존재하지 않습니다."라는 오류가 나타납니다. . 따라서 나는 내 자신의 DLL을 컴파일 할 수 없습니다 .. 내가 뭘 잘못하고 있는지 생각해? –

0

:

은 전체 라인 셀 스타일을 좋아하는 경우에, OnMouseOver 또는 IsSelected 사용이 :

<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}"> 
    <Setter Property="Foreground" Value="Green" /> 
     <Style.Triggers> 
      <!-- Full Row --> 
      <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGridRow}, Path=IsMouseOver}" Value="True"> 
       <Setter Property="Foreground" Value="Red" /> 
       <Setter Property="Opacity" Value="0.8" /> 
      </DataTrigger> 
      <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGridRow}, Path=IsSelected}" Value="True"> 
       <Setter Property="Foreground" Value="DeepPink" /> 
       <Setter Property="Opacity" Value="0.3" /> 
      </DataTrigger> 
     </Style.Triggers> 
</Style> 

세포에만이 :

<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}"> 
    <Setter Property="Foreground" Value="Green" /> 
     <Style.Triggers> 
      <!-- Cell only --> 
      <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True"> 
       <Setter Property="Foreground" Value="Red" /> 
        <Setter Property="Opacity" Value="0.8" /> 
      </DataTrigger> 
      <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsSelected}" Value="True"> 
       <Setter Property="Foreground" Value="DeepPink" /> 
       <Setter Property="Opacity" Value="0.3" /> 
      </DataTrigger> 
     </Style.Triggers> 
</Style> 

전체 응용 프로그램에서 작동하도록 app.xaml에 Style을 배치 할 수 있습니다.

+0

나는 그것을 복잡하게 만들고 싶다고 생각한다. 귀하의 솔루션은 나를 위해 아주 잘 작동합니다. 고맙습니다! 그러나 내가 가지고있는 질문이 하나 더 있습니다.이 행의 불투명도를 줄일 수 있습니까? 그래서 그것은 조금 가볍게 누른 다음 선택한 것입니다? 불투명도가 감소되었지만 작동하지 않는 다른 답변에서 코드 스 니펫을 사용하려고 시도했습니다 ... –

+0

업데이트 된 답변보기. 대답을 upvote하는 것을 잊지 마세요! – WPFGermany

+0

음, 배경에 대해 불투명도를 변경하는 것도 가능합니까? 이제 전체 행 (Fore- 및 Backrgound)에 대해 변경됩니다. 또 다른 문제 : 다른 색상을 설정하는 다른 Style.xaml 파일이 있습니다. 런타임에 나는 그들을 변경하고 application.xaml에서 그들을 대체 할 수 있지만 내가 이것을 할 때 Foregroundcolor의 값은 업데이트되지 않을 것입니다 - 항상로드 된 xaml 파일에 정의 된 것처럼 유지됩니다 .. –