WPFExamples is a trial ground project to show case different components in Windows Presentation Foundation (WPF) framework using C#. The goal is the show example implementations of each component, categorically and logically organized. In some cases, allow the user to see existing examples and in few limited cases even control the parameters and see how the changes look in real time for simple Controls.
Note: The primary purpose is to get a look and feel on how an UI element is visible and how we can control it. Not learn how to code it.
If you want to learn about WPF, there are some nice tutorials available online.
- BasicControls
- Feature.Infrastructure
- WPF_Components_Demo
- DotnetFrameworkReferenceLibraries (Submodule)
- Architectural Overview
- Code Schema
- How to Extend
- License
- Role: Provides infrastructure code that defines interfaces needed for Feature based Demonstrations. This will be Foundational project that other Feature Project will depend on
- Key Interfaces:
IFeatureDemoTopic
- This is the primary contract that new Demo Classes will implement(i.e. Controls). This Topic and its SubTopics are directly displayed in Table of Contents for Demo.IFeatureDemoSubTopic
- This is the contract for the sub topics (i.e. Buttons, Labels, ComboBoxes) etcISubTopicMetadata
- Metadata needed for SubTopic to be binded to Topic (i.e. Topic: Control, SubTopic: Button Examples)
- Role: Contains reference libraries for .NET Framework integration, enabling extended functionality and compatibility for WPF projects.
- Role: Contains demos and sample code for foundational WPF controls (buttons, textboxes, etc.), illustrating customization and event handling.
Info These are to be created as WPF .Net Framework Class Libraries. They should output their binaries to $(SolutionDir)/bin/$(Configuration)/FeaturesDemo
folder for MEF to pickup
Role This porject is created to showcase basic controls like Label, TextBox, TextBlock, Combobox etc.
The repository follows a modular architecture:
- UI Layer: (BasicControls, WPF_Components_Demo)
- Focuses on presentation, user interaction, and UI customization.
- Infrastructure Layer: (Feature.Infrastructure)
- Handles business logic, data access, and common utilities.
- External Libraries: (DotnetFrameworkReferenceLibraries)
- Provides additional .NET Framework capabilities as needed.
Each module is self-contained but designed to interoperate via shared interfaces and data models.
Here’s an example schema describing typical structure:
WPFExamples/
│
├── BasicControls/
│ ├── ButtonDemo.xaml.cs
│ ├── TextBoxDemo.xaml.cs
│ └── ...
├── Feature.Infrastructure/
│ ├── Service/
│ │ └── LoggingService.cs
│ ├── Helpers/
│ │ └── DataHelper.cs
│ └── ...
├── WPF_Components_Demo/
│ ├── MainWindow.xaml.cs
│ ├── ViewModels/
│ │ └── MainViewModel.cs
│ └── ...
├── DotnetFrameworkReferenceLibraries/ (submodule)
│ └── ...
└── WPFExamples.sln
To add a new demo for a feature, for example a demo for SubTopic Border
under Topic Additional Controls
, follow these steps:
- Reuse an existing Addin Project created earlier for
Additional Controls
OR - Create a new .Net Framework WPF Class Library. Call it
AdditionalControls
- For this example I am assuming the latter
- Set its output Directory to
$(SolutionDir)/bin/$(Configuration)/Addons
- Add a new FeatureDemoTopic and SubFeatureDemoTopic classes:
// AdditionalControls/BorderExample.cs
namespace AdditionalControls
{
public class AddonMetadataKeys // <-- Can be Any Name
{
public const string AdditionalControlsTitle = "Additional Controls";
public const string BorderControlTitle = "Border Controls";
}
[Export(typeof(IFeatureDemoTopic))]
public class AdditionalControls : FeatureDemoTopic
{
public override string Title => AddonMetadataKeys.AdditionalControlsTitle; // <-- Topic Name
}
[Export(typeof(IFeatureDemoSubTopic))]
[ExportMetadata(MetaDataKeys.TopicName, AddonMetadataKeys.AdditionalControlsTitle)] // <-- pass Topic Name
public class BorderSubTopic : IFeatureDemoSubTopic
{
public string Title => AddonMetadataKeys.BorderControlTitle; // <-- Set the SubTopic, aka Control Name
}
}
-
Add a new Window for the UI: .xaml and backing .cs
<!-- AdditionalControls/Border/borderDemoView.xaml --> <UserControl x:Class="AdditionalControls.Border.BorderDemoView" ...> <StackPanel> <TextBlock Text="Different Border Styles in WPF" FontSize="18" FontWeight="Bold" Margin="0,0,0,10" HorizontalAlignment="Center"/> <ItemsControl ItemsSource="{Binding Samples}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical" > ... </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </StackPanel> </UserControl>
namespace AdditionalControls.Border { /// <summary> /// Interaction logic for BorderDemoView.xaml /// </summary> public partial class BorderDemoView : UserControl { public BorderDemoView() { InitializeComponent(); } } }
-
Add viewmodel AdditionalControls.Border.BorderDemoViewModel
internal class BorderDemoViewModel : ControlDemoViewModel<BorderProperties> { public BorderDemoViewModel() { Header = "Samples of Border control in WPF"; // <-- Give some text as header // Initialize the collection `Samples` with some sample data Samples = new ObservableCollection<BorderProperties> { ... }; } }
-
Add model AdditionalControls.Border.BorderExample
internal class BorderProperties {} // add any properties you want to control
See LICENSE.txt for details.