Skip to content

Commit

Permalink
Added sample application for usage of common dialogs in WPF
Browse files Browse the repository at this point in the history
Added sample application for usage of common dialogs in WPF
  • Loading branch information
dipeshmsft authored Aug 24, 2023
2 parents 761ba66 + d7fe047 commit 7530fd2
Show file tree
Hide file tree
Showing 10 changed files with 533 additions and 2 deletions.
23 changes: 21 additions & 2 deletions WPFSamples.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28927.53
# Visual Studio Version 17
VisualStudioVersion = 17.7.33711.374
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample Applications", "Sample Applications", "{122369C4-906B-4398-9F7D-DA33916262CF}"
EndProject
Expand Down Expand Up @@ -519,6 +519,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpellChecking", "Documents\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomDictionaries", "Documents\Spell Checking\CustomDictionaries\CustomDictionaries.csproj", "{CF0B6854-6CA8-4BAC-AF72-E97AE1E54593}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonDialogs", "Windows\CommonDialog\CommonDialogs.csproj", "{41E866EB-A376-47B0-AADA-FC59ACE90A69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -3858,6 +3860,22 @@ Global
{CF0B6854-6CA8-4BAC-AF72-E97AE1E54593}.Release|x64.Build.0 = Release|Any CPU
{CF0B6854-6CA8-4BAC-AF72-E97AE1E54593}.Release|x86.ActiveCfg = Release|Any CPU
{CF0B6854-6CA8-4BAC-AF72-E97AE1E54593}.Release|x86.Build.0 = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|ARM64.Build.0 = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|x64.ActiveCfg = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|x64.Build.0 = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|x86.ActiveCfg = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Debug|x86.Build.0 = Debug|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|Any CPU.Build.0 = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|ARM64.ActiveCfg = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|ARM64.Build.0 = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|x64.ActiveCfg = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|x64.Build.0 = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|x86.ActiveCfg = Release|Any CPU
{41E866EB-A376-47B0-AADA-FC59ACE90A69}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -4113,6 +4131,7 @@ Global
{8B9A2506-290B-4E20-ABA9-05A89F020809} = {F9BFF0BB-9124-49AE-8482-32A126D58AD2}
{74949E7C-71B0-4E03-8EC3-7CCA9E01397D} = {8B9A2506-290B-4E20-ABA9-05A89F020809}
{CF0B6854-6CA8-4BAC-AF72-E97AE1E54593} = {8B9A2506-290B-4E20-ABA9-05A89F020809}
{41E866EB-A376-47B0-AADA-FC59ACE90A69} = {168E363A-7B91-4FBF-A393-28BD29C818DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5999CD15-1B95-49B3-AD12-5FDC10B2FBAD}
Expand Down
9 changes: 9 additions & 0 deletions Windows/CommonDialog/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="CommonDialog.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CommonDialog"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
13 changes: 13 additions & 0 deletions Windows/CommonDialog/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace CommonDialog
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions Windows/CommonDialog/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
70 changes: 70 additions & 0 deletions Windows/CommonDialog/CommonDialogs.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnableDefaultItems>false</EnableDefaultItems>
<UseWPF>true</UseWPF>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F1A89776-516D-4196-9E4F-1F92090E8D5B}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonDialogs</RootNamespace>
<AssemblyName>CommonDialogs</AssemblyName>
<FileAlignment>512</FileAlignment>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="DialogDataModel.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="RelayCommand.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainWindowViewModel.cs" />
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
64 changes: 64 additions & 0 deletions Windows/CommonDialog/DialogDataModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.ComponentModel;

namespace CommonDialogs
{
class DialogDataModel : INotifyPropertyChanged
{
# region Data Fields and Properties

private string resultTitle = "";
private string resultBody = "";
private string dialogDescription = "";
private string clickOperationDescription = "";

public string ResultTitle
{
get => resultTitle;
set
{
resultTitle = value;
OnPropertyChanged(nameof(ResultTitle));
}
}

public string ResultBody
{
get => resultBody;
set
{
resultBody = value;
OnPropertyChanged(nameof(ResultBody));
}
}

public string DialogDescription
{
get => dialogDescription;
set
{
dialogDescription = value;
OnPropertyChanged(nameof(DialogDescription));
}
}

public string ClickOperationDescription
{
get => clickOperationDescription;
set
{
clickOperationDescription = value;
OnPropertyChanged(nameof(ClickOperationDescription));
}
}

#endregion

private void OnPropertyChanged(string v)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(v));
}

public event PropertyChangedEventHandler? PropertyChanged;

}
}
65 changes: 65 additions & 0 deletions Windows/CommonDialog/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<Window x:Class="CommonDialogs.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CommonDialogs" mc:Ignorable="d"
Title="WPF Dialogs Sample Application" Height="500" Width="800">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Window.Resources>
<Style x:Key="DialogButtonStyle" TargetType="Button">
<Setter Property="Margin" Value="5"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="30"/>
</Style>
</Window.Resources>
<DockPanel LastChildFill="True">
<RichTextBox DockPanel.Dock="Top">
<FlowDocument>
<Paragraph FontSize="16" FontWeight="Bold" Margin="0" Padding="0">WPF Dialogs Sample</Paragraph>
<Paragraph Margin="0" Padding="2">
<Run Text="This is a sample application that shows how to use File and Folder dialogs in WPF. "/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="240"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="0" Grid.Row="0">
<Button Content="Open File" Command="{Binding OpenFileCommand}" Style="{StaticResource DialogButtonStyle}"/>
<Button Content="Save File" Command="{Binding SaveFileCommand}" Style="{StaticResource DialogButtonStyle}"/>
<Button Content="Open Folder" Command="{Binding OpenFolderCommand}" Style="{StaticResource DialogButtonStyle}"/>
</StackPanel>
<Border Grid.Column="1" BorderThickness="2,0,2,0" BorderBrush="Black">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<RichTextBox BorderThickness="0">
<FlowDocument>
<Paragraph FontSize="16" FontWeight="Bold">
<Run Text="{Binding Data.ResultTitle}" />
</Paragraph>
<Paragraph>
<Run Text="{Binding Data.ResultBody}" />
</Paragraph>
</FlowDocument>
</RichTextBox>
</ScrollViewer>
</Border>
<StackPanel Orientation="Vertical" Grid.Column="2">
<TextBlock Text="Description" FontWeight="Bold" Margin="10,5" />
<TextBlock TextWrapping="Wrap" Text="{Binding Data.DialogDescription, Mode=OneWay}" Margin="10,5"/>
<Separator BorderBrush="Black" BorderThickness="0,0,0,1" Margin="0,5,0,5"/>
<TextBlock Text="Click Button Operation" FontWeight="Bold" Margin="10,5" />
<TextBlock TextWrapping="Wrap" Text="{Binding Data.ClickOperationDescription, Mode=OneWay}" Margin="10,5"/>
</StackPanel>
</Grid>
</DockPanel>
</Window>
29 changes: 29 additions & 0 deletions Windows/CommonDialog/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using static System.Net.Mime.MediaTypeNames;

namespace CommonDialogs
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
Loading

0 comments on commit 7530fd2

Please sign in to comment.