forked from microsoft/WPF-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sample application for usage of common dialogs in WPF
Added sample application for usage of common dialogs in WPF
- Loading branch information
Showing
10 changed files
with
533 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.