2 |
Unicorn.ViewManager
3 |
4 | A powerful WPF view management library
5 |
6 |
7 | Supporting .NET Core (3.1)
8 |
9 |
10 |
11 |
12 | ## Installation
13 | - [Nuget](https://www.nuget.org/packages/Unicorn.ViewManager/)
14 |
15 | ```
16 | PM> Install-Package Unicorn.ViewManager
17 | ```
18 |
19 | ## Let's get started
20 | To start, first add this code at MainWindow's constructor.This step is to initialize a main view stack. ViewManager.Instance.MainRichView.SwitchView(object) method is used to switch the main view in the program,it does not belong to the view stack.
21 | ```csharp
22 | public MainWindow()
23 | {
24 | InitializeComponent();
25 |
26 | ViewManager.Instance.InitializeRichView(this);
27 | ViewManager.Instance.ViewPreferences.UsePopupViewAnimations = true;
28 | ViewManager.Instance.MainRichView.SwitchView(new MainView());
29 | }
30 | ```
31 | The second step is to initialize a Unicorn.ViewManager.Dialog or Unicorn.ViewManager.Flyout,you can inherit it in xaml,when you have a Unicorn.ViewManager.Dialog or Unicorn.ViewManager.Flyout,.
32 | you can display it with ViewManager.Instance.Show(PopupItem item) method.
33 | ```csharp
34 | ViewManager.Instance.Show(new FullScreenDialog());//FullScreenDialog is my Dialog instance inherit Dialog
35 | //OR
36 | new FullScreenDialog().Show();//at default main view stack
37 | //OR
38 | new FullScreenDialog().Show(IPopupItemContainer );//IPopupItemContainer is a interface
39 | //OR
40 | new FullScreenDialog().ShowAsModal();//at default main view stack
41 | //OR
42 | new FullScreenDialog().ShowAsModal(IPopupItemContainer );//at custom IPopupItemContainer
43 | ```
44 | you can close it like that.
45 | ```csharp
46 | ViewManager.Instance.Close(Dialog dialog);//FullScreenDialog is my Dialog instance inherit Dialog
47 | //OR
48 | dialog.Close();
49 | ```
50 |
51 | ## View's events
52 | Each view item has four events, they are 'Showing','Shown','Closing','Closed'.
53 | 'Showing','Closing' can be canceled. you can use it like that:
54 | ```csharp
55 | public partial class DialogWithEvent : Dialog
56 | {
57 | public DialogWithEvent()
58 | {
59 | InitializeComponent();
60 | this.Showing += DialogWithEvent_Showing;
61 | this.Shown += DialogWithEvent_Shown;
62 | this.Closing += DialogWithEvent_Closing;
63 | this.Closed += DialogWithEvent_Closed;
64 | }
65 |
66 | private void DialogWithEvent_Closed(object sender, EventArgs e)
67 | {
68 | MessageDialogBox.Show("该Dialog已彻底关闭,并已从视图栈移除,可在此事件处理中处理一些释放问题", "信息", MessageBoxButton.OK, MessageBoxImage.Information);
69 | }
70 |
71 | private void DialogWithEvent_Closing(object sender, System.ComponentModel.CancelEventArgs e)
72 | {
73 | var msresult = MessageDialogBox.Show("Dialog With Event 准备关闭,此时可以取消,是否继续关闭", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
74 | if (msresult == MessageBoxResult.No)
75 | {
76 | e.Cancel = true;
77 | }
78 | }
79 |
80 | private void DialogWithEvent_Shown(object sender, EventArgs e)
81 | {
82 | MessageDialogBox.Show("该Dialog已显示完成,可在此事件处理中处理一些加载问题", "信息", MessageBoxButton.OK, MessageBoxImage.Information);
83 | }
84 |
85 | private void DialogWithEvent_Showing(object sender, System.ComponentModel.CancelEventArgs e)
86 | {
87 | var msresult = MessageDialogBox.Show("Dialog With Event 准备显示,此时可以取消,是否继续显示", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
88 | if (msresult == MessageBoxResult.No)
89 | {
90 | e.Cancel = true;
91 | }
92 | }
93 | }
94 | ```
95 | See more details in the demo.
96 |
97 |
98 | ## Screenshots
99 | 
100 | 
101 | 
102 | 
103 | 
104 | 
105 | 
106 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/src/Unicorn.ViewManager/RichViewControl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 | using System.Windows.Controls.Primitives;
7 | using System.Windows.Data;
8 | using System.Windows.Documents;
9 | using System.Windows.Input;
10 | using System.Windows.Media;
11 | using System.Windows.Media.Imaging;
12 | using System.Windows.Navigation;
13 | using System.Windows.Shapes;
14 | using Unicorn.Utilities;
15 |
16 | namespace Unicorn.ViewManager
17 | {
18 | public interface IRichViewContainer
19 | {
20 | void ShowView(object item);
21 | void CloseView(object item);
22 | void SwitchView(object item);
23 | }
24 |
25 | [TemplatePart(Name = PART_POPUPSTACKCONTROL, Type = typeof(ContentPresenter))]
26 | public class RichViewControl : ItemsControl, IRichViewContainer, IPopupItemContainer
27 | {
28 | private const string PART_POPUPSTACKCONTROL = "PART_POPUPSTACKCONTROL";
29 |
30 | private readonly PopupStackControl _popupStackControl = null;
31 |
32 | public PopupStackControl PopupStackControl
33 | {
34 | get
35 | {
36 | return this._popupStackControl;
37 | }
38 | }
39 |
40 | public PopupItem TopItem => this.PopupStackControl.TopItem;
41 |
42 | IPopupItemContainer IPopupItemContainer.Parent => ((IPopupItemContainer)this.PopupStackControl).Parent;
43 |
44 | public IEnumerable