あなたのケースでは、AccentColor4
の値に基づいてAccent
(おそらくAccentColor5
?)に新しいキーを追加すると思います。
Hereあなたは(CreateAppStyleBy
メソッドを参照してください)AccentColor4
からAccentColor5
を計算に役立つかもしれないpunker76によって作られたThemeManagerHelper
クラスを、見つけることができます。 - キーを現在のAccent
にアプリケーションの
private void AddKeyForCurrentAccent(object key, object value, bool changeAccentImmediately = false)
{
Tuple<MahApps.Metro.AppTheme, MahApps.Metro.Accent> currentAppStyle = MahApps.Metro.ThemeManager.DetectAppStyle(Application.Current);
if(currentAppStyle.Item2.Resources.Contains(key))
{
currentAppStyle.Item2.Resources.Remove(key);
}
currentAppStyle.Item2.Resources.Add(key, value);
if(changeAccentImmediately)
{
var accentName = string.Format("CustomTheme.xaml");
CreateAccentFrom(accentName, currentAppStyle.Item2.Resources);
MahApps.Metro.ThemeManager.ChangeAppStyle(Application.Current, MahApps.Metro.ThemeManager.GetAccent(accentName), currentAppStyle.Item1);
}
}
private void CreateAccentFrom(string accentName, ResourceDictionary resourceDictionary)
{
var fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), accentName);
using (var writer = System.Xml.XmlWriter.Create(fileName, new System.Xml.XmlWriterSettings { Indent = true }))
{
System.Windows.Markup.XamlWriter.Save(resourceDictionary, writer);
writer.Close();
}
resourceDictionary = new ResourceDictionary() { Source = new Uri(fileName, UriKind.Absolute) };
var newAccent = new MahApps.Metro.Accent { Name = accentName, Resources = resourceDictionary };
MahApps.Metro.ThemeManager.AddAccent(accentName, newAccent.Resources.Source);
}
AddKeyForCurrentAccent
追加(それがすでに存在する場合または交換)します:
私はまた、あなたの人生を容易にするべきである、これを作りました。 changeAccentImmediately
がtrueに設定されている
場合は、新しいファイルを作成し、新しいAccent
(挿入と/置き換えキー)を保存し、アプリケーション
TIPためAccent
として設定:あなたが追加することができます/あなたが望むすべてのキーを置き換え、changeAccentImmediately
をtrueに設定するのは最後のものだけです(これによりパフォーマンスが向上します)。
AddKeyForCurrentAccent("AccentColor5", Brushes.Pink); // Does not replace the accent immediately (so changes are not visible) - works faster
// AND/OR
AddKeyForCurrentAccent("AccentColor5", Brushes.HotPink, true); // Will update the UI
重要:カスタムキーを使用して、あなたのAccent
に追加するのを忘れた場合、それはその型のデフォルト値を使用しますので、予めご了承ください
はこのようにそれを使用します。
幸運を祈る!
私は同様の質問[ここ](http://stackoverflow.com/questions/36147698/how-to-create-a-custom-accent-in-mahapps-metro/36169095#36169095)に答えました。 – jsanalytics
@jstreetなので、既存のMahAppsのアクセントをコピーして新しいアクセントを作成し、新しい色を追加する必要がありますか?それは残念です - 私はちょうど1つの特定の色のより軽いバージョンが必要なので、何とかそれを継承または上書きする巧妙な方法があることを望んでいた、または不透明度を変更します。私は私のデザインについて考え直すだろう... –