2016-04-26 35 views
2

Aus Gründen der Anpassung für MessageBox Stil, ich benutze dieses Toolkit, und ich kopieren Sie den Stil-Code von seiner offiziellen Seite:WPF - Passen Sie den Stil von MessageBox in der erweiterten WPF Toolkit

http://wpftoolkit.codeplex.com/wikipage?title=MessageBox&referringTitle=Documentation

I geändert es ist ein bisschen:

<Application x:Class="TotaraEditor.App" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:local="clr-namespace:TotaraEditor" 
      xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit" 
      StartupUri="MainWindow.xaml" 
      ShutdownMode="OnMainWindowClose"> 
    <Application.Resources> 
     <ResourceDictionary> 
      <ResourceDictionary.MergedDictionaries> 
       <ResourceDictionary Source="Themes/MetroDark/MetroDark.MSControls.Core.Implicit.xaml" /> 
       <ResourceDictionary Source="Themes/MetroDark/MetroDark.MSControls.Toolkit.Implicit.xaml" /> 
      </ResourceDictionary.MergedDictionaries> 

      <SolidColorBrush x:Key="MyButtonHoverBrush" Color="#FF2D2D30" /> 
      <SolidColorBrush x:Key="MyButtonPressedBrush" Color="#FF03A9DD" /> 

      <Style x:Key="MyCloseButtonStyle" TargetType="Button"> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="Button"> 
          <Grid> 
           <VisualStateManager.VisualStateGroups> 
            <VisualStateGroup x:Name="CommonStates"> 
             <VisualState x:Name="Normal"/> 
             <VisualState x:Name="MouseOver"> 
              <Storyboard> 
               <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background)"> 
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource MyButtonHoverBrush}"></DiscreteObjectKeyFrame> 
               </ObjectAnimationUsingKeyFrames> 
              </Storyboard> 
             </VisualState> 
             <VisualState x:Name="Pressed"> 
              <Storyboard> 
               <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Border.Background)"> 
                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource MyButtonPressedBrush}"></DiscreteObjectKeyFrame> 
               </ObjectAnimationUsingKeyFrames> 
              </Storyboard> 
             </VisualState> 
            </VisualStateGroup> 
           </VisualStateManager.VisualStateGroups> 
           <Border x:Name="Background" CornerRadius="0,0,0,0" Background="Green"> 
            <Border Margin="1,0,1,1" BorderBrush="#59FFFFFF" BorderThickness="1" CornerRadius="0,0,1,0"/> 
           </Border> 
           <ContentPresenter x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/> 
           <Path x:Name="path" Fill="White" Margin="0,0,0,1" Visibility="Collapsed" 
        Height="60" 
     Width="7" 
     Stretch="Fill" 
     Opacity="1" 
     Data="M 2,6 C2,6 3,6 3,6 3,6 3,5 3,5 3,5 4,5 4,5 4,5 4,6 4,6 4,6 5,6 5,6 5,6 7,6 7,6 7,6 7,5 7,5 7,5 6,5 6,5 6,5 6,4 6,4 6,4 5,4 5,4 5,4 5,2 5,2 5,2 6,2 6,2 6,2 6,1 6,1 6,1 7,1 7,1 7,1 7,0 7,0 7,0 5,0 5,0 5,0 4,0 4,0 4,0 4,1 4,1 4,1 3,1 3,1 3,1 3,0 3,0 3,0 2,0 2,0 2,0 0,0 0,0 0,0 0,1 0,1 0,1 1,1 1,1 1,1 1,2 1,2 1,2 2,2 2,2 2,2 2,4 2,4 2,4 1,4 1,4 1,4 1,5 1,5 1,5 0,5 0,5 0,5 0,6 0,6 0,6 2,6 2,6 z"/> 
          </Grid> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 

      <Style TargetType="{x:Type toolkit:MessageBox}"> 
       <Setter Property="Background" Value="#FF1E1E1E" /> 
       <Setter Property="BorderBrush" Value="#FF999999" /> 
       <Setter Property="CaptionForeground" Value="#FFF1F1F1" /> 
       <Setter Property="WindowBorderBrush" Value="#FF686868" /> 
       <Setter Property="WindowBackground" Value="#FF2D2D30" /> 
       <Setter Property="WindowOpacity" Value="0.3" /> 
       <Setter Property="Foreground" Value="#FFF1F1F1"/> 
       <Setter Property="CloseButtonStyle" Value="{StaticResource MyCloseButtonStyle}"/> 
      </Style> 



     </ResourceDictionary> 

    </Application.Resources> 
</Application> 

Dies ist, wie ich es hinter im Code verwenden:

var res = Xceed.Wpf.Toolkit.MessageBox.Show( 
          "R U sure?", 
          "Confirm dialog", 
          MessageBoxButton.YesNoCancel, 
          MessageBoxImage.None, 
          MessageBoxResult.Cancel, 
          null 
         ); 
if ("Cancel" == res.ToString()) {...} 
else if ("No" == res.ToString()) {...} 
else if ("Yes" == res.ToString()) {...} 
else {...} 

Und jetzt, was ich habe ist: enter image description here

Da es keine Möglichkeit gibt, die XAML dieser Tasten zu berühren, wie soll ich die Tasten Stil ändern? Zumindest möchte ich den leuchtenden Effekt des Headers entfernen.

Danke.

UPDATE

Ich bin sicher, dass die leuchtende Wirkung wird von einigem Stil auf das Etikett aufgebracht nicht verursacht, es ist ein Stil Rechteck unter dem Label ist, fand ich diesen in WPF-Inspektoren:

enter image description here

Nachdem ich die Höhe dieses Rect auf 0 gesetzt habe, verschwand dieses leuchtende Ding.

enter image description here

private void Window_Loaded(object sender, RoutedEventArgs e) 
    { 
     Xceed.Wpf.Toolkit.MessageBox mbox = new Xceed.Wpf.Toolkit.MessageBox(); 
     mbox.OkButtonStyle = (Style)Resources["ButtonStyle1"]; 
     mbox.OkButtonContent = "Click Me !"; 
     mbox.Caption = "My custom caption"; 
     mbox.Text = "My custom message"; 
     mbox.ShowDialog(); 
    } 

XAML:

Antwort

3

können Sie auf die Schaltfläche Stil wie das ändern

<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> 
     <Setter Property="Background" Value="Green"></Setter> 
     <Setter Property="Foreground" Value="White"></Setter> 
    </Style> 

Was die leuchtende Wirkung in Ihrem Titel, müssen Sie den Stil ändern Sie kopiert von dem Link, den Sie entsprechend gepostet haben, oder erstellen Sie Ihren eigenen Stil.

EDIT: Verwendung MetroDark style:

enter image description here

private void Window_Loaded(object sender, RoutedEventArgs e) 
    { 
     var res = Xceed.Wpf.Toolkit.MessageBox.Show(
          "R U sure?", 
          "Confirm dialog", 
          MessageBoxButton.YesNoCancel, 
          MessageBoxImage.None, 
          MessageBoxResult.Cancel, 
          (Style)Resources["MessageBoxStyle1"] 
         ); 

     if ("Cancel" == res.ToString()) 
     { 
     } 
     else if ("No" == res.ToString()) 
     { 
     } 
     else if ("Yes" == res.ToString()) 
     { 
     } 
     else 
     { 
     } 
    } 

XAML:

 <Style x:Key="ButtonStyle1" TargetType="Button"> 
      <Setter Property="Background" Value="LightGreen"></Setter> 
      <Setter Property="Foreground" Value="DarkGreen"></Setter> 
     </Style> 
     <Style x:Key="ButtonStyle2" TargetType="Button"> 
      <Setter Property="Background" Value="LightCoral"></Setter> 
      <Setter Property="Foreground" Value="DarkRed"></Setter> 
     </Style> 
     <Style x:Key="ButtonStyle3" TargetType="Button"> 
      <Setter Property="Background" Value="LightYellow"></Setter> 
      <Setter Property="Foreground" Value="DarkOrange"></Setter> 
     </Style> 

     <Style x:Key="MessageBoxStyle1" TargetType="{x:Type xctk:MessageBox}"> 
      <Setter Property="Background" Value="#FF1E1E1E" /> 
      <Setter Property="BorderBrush" Value="#FF999999" /> 
      <Setter Property="CaptionForeground" Value="#FFF1F1F1" /> 
      <Setter Property="WindowBorderBrush" Value="#FF686868" /> 
      <Setter Property="WindowBackground" Value="#FF2D2D30" /> 
      <Setter Property="WindowOpacity" Value="0.3" /> 
      <Setter Property="Foreground" Value="#FFF1F1F1"/> 
      <Setter Property="CloseButtonStyle" Value="{StaticResource MyCloseButtonStyle}"/> 
      <Setter Property="YesButtonStyle" Value="{StaticResource ButtonStyle1}"></Setter> 
      <Setter Property="NoButtonStyle" Value="{StaticResource ButtonStyle2}"></Setter> 
      <Setter Property="CancelButtonStyle" Value="{StaticResource ButtonStyle3}"></Setter> 
     </Style> 

EDIT 2: Die Beschriftung Glanz auf der CaptionShadowBrush verbunden:

 <Setter Property="CaptionShadowBrush" Value="LightCoral"></Setter> 

enter image description here

Sie können entweder es Transparent gesetzt oder ganz es loswerden:

 <Setter Property="CaptionShadowBrush" Value="Transparent"></Setter> 
+0

Danke jstreet, ich die Frage aktualisiert, wie Sie sehen können, in dem Stück Code für Stil, ich habe nichts in Bezug auf den leuchtenden Effekt gesehen, der Großteil des Codes ist über Button-Stil. – VincentZHANG

+0

Auf der anderen Seite bin ich die MessageBox mit Benutzern Entscheidung zu bekommen: "RU sicher" 'var res = Xceed.Wpf.Toolkit.MessageBox.Show ( , "Confirm Dialog", MessageBoxButton.YesNoCancel, MessageBoxImage .None, MessageBoxResult.Cancel, null ); if ("Abbrechen" == res.ToString()) {...} sonst if ("Nein" == res.ToString()) {...} sonst if ("Ja" == res. ToString()) {...} sonst {...} ' – VincentZHANG

+0

@VincentZHANG bitte den Stil als Text, nicht als Druck-Bildschirm, so dass die Leute es kopieren können. Bitte verschieben Sie den Code von Ihrem Kommentar zu Ihrem Post und klären Sie genau, was Sie dann brauchen. – jsanalytics