# Resource Dictionary Architecture / Kiến Trúc Resource Dictionary ## Overview / Tổng Quan Resource Dictionary là nền tảng của Design System trong .NET MAUI. Việc tổ chức đúng cách giúp: - **Re-branding dễ dàng**: Chỉ cần thay đổi 1 file - **Maintainability**: Code UI sạch, không lặp lại - **Consistency**: Đảm bảo UI đồng nhất toàn app --- ## Directory Structure / Cấu Trúc Thư Mục ``` Resources/ ├── Styles/ │ ├── Colors.xaml # Bảng màu chính │ ├── Typography.xaml # Font families, sizes │ ├── Spacing.xaml # Margins, paddings │ └── Theme.xaml # Styles cho controls ├── Fonts/ │ ├── Inter-Regular.ttf │ └── Inter-Bold.ttf └── Images/ ├── logo.svg └── icons/ ``` --- ## 1. Colors.xaml - Bảng Màu ### Nguyên tắc đặt tên - **Brand Colors**: `Brand*` (Primary, Secondary, Accent) - **Semantic Colors**: `Color*` (Success, Warning, Error, Info) - **Surface Colors**: `Surface*` (Background, Card, Overlay) - **Text Colors**: `Text*` (Primary, Secondary, Disabled) ### Complete Example ```xml #2196F3 #1976D2 #64B5F6 #FF5722 #4CAF50 #FF9800 #F44336 #2196F3 {AppThemeBinding Light=#FAFAFA, Dark=#121212} {AppThemeBinding Light=#FFFFFF, Dark=#1E1E1E} {AppThemeBinding Light=#00000033, Dark=#FFFFFF33} {AppThemeBinding Light=#212121, Dark=#FFFFFF} {AppThemeBinding Light=#757575, Dark=#B0B0B0} {AppThemeBinding Light=#9E9E9E, Dark=#616161} #FFFFFF {AppThemeBinding Light=#E0E0E0, Dark=#424242} {StaticResource BrandPrimary} ``` --- ## 2. Typography.xaml - Font & Text Styles ### Font Registration (MauiProgram.cs) ```csharp builder.ConfigureFonts(fonts => { fonts.AddFont("Inter-Regular.ttf", "InterRegular"); fonts.AddFont("Inter-Medium.ttf", "InterMedium"); fonts.AddFont("Inter-Bold.ttf", "InterBold"); fonts.AddFont("Inter-SemiBold.ttf", "InterSemiBold"); }); ``` ### Typography Scale ```xml 12 16 18 24 32 48 ``` --- ## 3. Theme.xaml - Control Styles ### Implicit vs Explicit Styles | Type | Syntax | Use Case | |------|--------|----------| | **Implicit** | ` ``` --- ## 4. Merged Dictionaries trong App.xaml ### Thứ tự quan trọng ```xml ``` --- ## Best Practices / Thực Hành Tốt Nhất ### ✅ DO ```xml