WPF를 사용하여 .net에서 Windows 응용 프로그램을 개발하려고합니다. 그래서 런타임에 동적 테마를 구현할 수 있습니다. 나는 이것에 관해 많은 것을 조사했다. 그러나 나는이 물건을 이해할 수 없다. app.xaml에 아래 줄을 추가하면 어떻게하면 직접 thing 줄을 추가 할 수 있는지 오류가 표시됩니다. "ExpressionDark"의 이름을 가진 파일은 없지만. 이 같은 App.Xaml의 테마를 병합 할 수 있습니다 :WPF의 동적 테마
0
A
답변
0
를 추가 전환하려면 - 시간, 가능한 가장 좋은 방법은 자원 사전, 컨트롤 스타일의 전체 메인 애플 리케이션이나 모든 컨트롤의 리소스에로드합니다.
public static ResourceDictionary GetThemeResourceDictionary(Uri theme)
{
if (theme != null)
{
return Application.LoadComponent(theme) as ResourceDictionary;
}
return null;
}
public static void ApplyTheme(this ContentControl control /* Change this to Application to use this function at app level */, string theme)
{
ResourceDictionary dictionary = GetThemeResourceDictionary(theme);
if (dictionary != null)
{
// Be careful here, you'll need to implement some logic to prevent errors.
control.Resources.MergedDictionaries.Clear();
control.Resources.MergedDictionaries.Add(dictionary);
// For app level
// app.Resources.MergedDictionaries.Clear();
// app.Resources.MergedDictionaries.Add(dictionary);
}
}
0
사전에
<ResourceDictionary Source="Themes/ExpressionDark.xaml"/>
***or***
<ResourceDictionary Source="ExpressionDark.xaml"/>
감사 :
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="defaulttheme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
defaulttheme.xaml 파일은 프로젝트의 루트에 있어야한다 . 당신이 일 테마에 대한 자신의 프로젝트를 빌드 싶은 경우에 당신은이 같은 자원을 병합 할 수 있습니다 :
여기<ResourceDictionary Source="/MyThemeProject;component/defaulttheme.xaml" />
defaulthteme.xaml 또한 루트에 MyThemeProject에 있어야하고 추가하는 것을 잊지에서 해당 프로젝트에 대한 참조를 추가하지 마십시오 귀하의 주요 프로젝트.
구조를 만들려면 원하는대로 폴더를 추가 할 수 있습니다.
<ResourceDictionary Source="/MyThemeProject;component/Folder1/Folder2/defaulttheme.xaml" />
는 테마 먼저 MergedDictionaries을 취소하고
DynamicThemes
에 의해, 당신은 실행에 테마를 넣어 의미한다고 가정하면 새 테마
NewTheme = new Uri(@"/MyThemeProject;component/folder1/Folder2/bluetheme.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(NewTheme);
감사
flusser
관련 문제
- 1. WPF의 동적 컨트롤 만들기
- 2. Wpf의 동적 변환기
- 3. WPF의 동적 마법사
- 4. WPF의 동적 테두리 구성
- 5. WPF의 동적 문자열 지역화
- 6. 동적 UI 테마
- 7. 동적 UI 스타일링/테마
- 8. asp.net의 동적 테마
- 9. WPF의 동적 DataGrid에 데이터 추가
- 10. WPF의 동적 백분율 기준 너비
- 11. WPF 테마 및 동적 컨트롤
- 12. Silverlight 및 WPF의 LINQ에서 동적 JOIN
- 13. WPF의 동적 컨트롤 - 가변 개수의 컨트롤 추가
- 14. 블랙 베리 테마 - 배경에 동적 텍스트 쓰기
- 15. Android의 동적 라디오 버튼에 테마 적용
- 16. jQuery Mobile // 내 동적 대화 상자 테마
- 17. WPF의 동적 컨트롤을 사용하지 않고 레이아웃 및 서식 지정
- 18. 동적으로 변경되는 테마
- 19. 페이지/임의의 HTML 요소에 테마/동적 CSS 적용
- 20. WPF의 SplitViewController
- 21. WPF의 조건부
- 22. WPF의 ReorderListView
- 23. WPF의 Menustrip
- 24. WPF의 DirectX.Sound
- 25. WPF의 LineChart
- 26. WPF의 문자표
- 27. wpf의 애니메이션
- 28. WPF의 MasterWindow
- 29. WPF의 해상도
- 30. WPF의 ContextMenu