code
1
μ°μ μ½λλ₯Ό λ¨Όμ λ³΄μ¬ λ리면
// App.Resources.xaml
<DataTemplate DataType="{x:Type plotvm:PlottingViewModel}">
<plotv:PlottingView />
</DataTemplate>
// PlottingViewModel.cs
public class PlottingViewModel : ReactiveObject, IContext
{
// ...
}
// PlottingView.xaml
<UserControl
x:Class="Uttu.Plotting.Views.PlottingView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:Uttu.Plotting.ViewModels"
d:DataContext="{d:DesignInstance vm:PlottingViewModel}"
mc:Ignorable="d">
// ....
</UserControl>
// DialogWindow.xaml
<Window
x:Class="Uttu.CAD.UI.DialogWindow"
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"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d">
</Window>
// DialogService.cs
public bool? ShowDialog(IContext content)
{
var dialog = new DialogWindow();
dialog.Content = content;
// ...
return dialoShowDialog();
}
μ΄λ κ² μ°κ³ μμ΅λλ€.
νλ©΄μ μ μμ μΌλ‘ λμ€κΈ΄ νλλ°
PlottingViewκ° λλ² μμ± λ©λλ€.
κ·Έλ¦¬κ³ κ°μ λ°©μμΌλ‘ λ€λ₯Έ dialog λ€λ μ°κ³ μλλ°
μ μ°½λ§ μ΄μνκ² binding λ κ°μ΄ μλ€μ΄ μ΅λλ€.
μ κ° λκ° μλͺ» μ°κ³ μλ κ±ΈκΉμ?
2κ°μ μ’μμ
Vincent
2
λ€ μ§κΈ μ½λμμλ λ λ² μμ±λλ κ²μ΄ λ§μ΅λλ€.
μ΄ μ½λλ λ·°λͺ¨λΈμ λ‘μΌμ΄ν°μ²λΌ κ°μ Έμμ μμ±ν©λλ€.
μ§κΈ μ½λλΌλ©΄ κ΅³μ΄ IContextκ° μκ³ Dialogμ Contentμ μ무κ²λ μμ΄λ μ μ½λ λλ¬Έμ Viewκ° μκΈΈ κ² κ°μ΅λλ€.
1κ°μ μ’μμ
μ½λλ λ¬Έμ μμ΄ λ³΄μ
λλ€.
μ¬ν λλ μ 체 νλ‘μ νΈλ₯Ό μ¬λ €μ£Όμ€ μ μλμ?
1κ°μ μ’μμ
code
4
μ΄κ²β¦ μ¬λ΄ νλ‘μ νΈλΌβ¦ μ 체 곡κ°λ μ΄λ €μ΅λλ€β¦
1κ°μ μ’μμ
Vincent
5
μ d:DesigneInstanceλΌλ κ±Έ μ κ° λͺ°λλ€μ.
μ°Ύμ보λκΉ μΈμ€ν΄μ€κ° ν λΉλλ κ·Έλ°κ² μλκ° λ³΄λ€μ.
νΌμ λλ € μ£μ‘ν©λλ€.
1κ°μ μ’μμ
μ¬νμ΄ λλ μ΅μνμ μ§μ ꡬννμ μν νλ‘μ νΈλΌλβ¦?
1κ°μ μ’μμ
code
7
μλλλ€. μ½μ΄ μ£Όμ
μ κ°μ¬ν©λλ€.
2κ°μ μ’μμ
code
8
μ΄κ² λ©μΉκ° μ’ μλ λ
μμ΄λΌβ¦ λ°λ‘λ μλ λ― νλ€μ.
μΌλ¨ μν λ§λ€λ©΄μ μ°Ύμλ΄μΌ κ² κ΅°μ.
κ°μ¬ν©λλ€.
2κ°μ μ’μμ
PlottingView μμ±μμ λΈλ μ΄ν¬ ν¬μΈν° μ°μ΄μ νμΈν΄λ³΄μμ£ . DataTemplateμμ λ§λλ건 μκ² λλ° κ·ΈμΈμ λ€λ₯Έμμ DIνκ±°λ ν λ μμ±λλμ§λ νμΈν΄λ΄μΌν κ² κ°μμ.
IContentλ‘ λμ΄μ€λ μΈμμλ ViewModelλ§ λμ΄μ€λ건 λ§μ£ ?
1κ°μ μ’μμ
code
10
μ€μ μμ€μμ title, position, resize mode λ± μ 보κ°λ§ λμ΄ μ€κ³ μ
μ΄κ±Έ μ°μμλ μ¬κΈ°κ° λλ² νλλ€.
μλλΆμ΄
https://blog.naver.com/vactorman/221014167271
μλ € μ£Όμ
μ λΆμμ€μ
λλ€.
λκΈ κ°μ¬ν©λλ€.
1κ°μ μ’μμ
@Greg.Lee λμ΄ μμ±νμ ν¬μ€νΈ λ΄μ©μ
Content λμ ViewModelμ΄ λ³κ²½ λ λ λ§λ€
Viewκ° μλ‘κ² λ§λ€μ΄ μ Έμ κ·Έμ μΊμμ²λ¦¬λ₯Ό νλ λ°©λ²μ λν ν¬μ€ν
μΈλ°
μ κ° μ΄ν΄ν μ§λ¬Έμλμ νμμ dialog.Content = content; μ Viewκ° λλ² μ°μ μμ± λλ λ¬Έμ λ‘ μ΄ν΄ νμ΅λλ€.
ViewModelμ΄ λ³κ²½ λ λ λ§λ€ Viewκ° λ§€λ² μμ±λλ λ¬Έμ λΌλ©΄ μ§κ·Ήν λΉμ°ν μ μμ μΈ νμμΌλ‘ μΊμλ±μΌλ‘ ν΄κ²°νμλ©΄ λ©λλ€.
1κ°μ μ’μμ
code
12
λ€ μμ λ§μ νμ λ΄μ©μ΄ λ§μ΅λλ€.
μμ λ§μνμ κ±°μ ShowDialog λ§ νλλ° ShowDialog λ΄λΆμμ Viewλ₯Ό λλ² μμ± νλ νμμ
λλ€.
μμ μ μ λΈλ‘κ·Έμμ λκ° ννΈκ° μλ μ°Ύκ³ μμμ΅λλ€.
(μμ°ν⦠보λλ° λͺ¬λ§μΈμ§ μ λͺ¨λ₯΄κ² μ΅λλ€β¦ μ΄λ ΅λ€μβ¦γ
.γ
)
1κ°μ μ’μμ
code
13
νβ¦ μν λ§λ€μ΄μ ν΄λ³΄λβ¦
1λ²λ§ λ€μ΄ μ€λ€μ.
λ¨Έκ° λ¬Έμ μ§ μ°Ύμ λ΄μΌ κ² μ΅λλ€.
2κ°μ μ’μμ
μ΄λ κ² κΈ°μ‘΄ μ½λμ λ¬Έμ κ° μμμ΄ μ¦λͺ
λμμΌλ.,
μ§κΈμ²λΌ μν λ§λ€μ΄μ
κΈ°μ‘΄ μ½λλ μνκ³Ό κ°μ΄ νλ νλμ© κ±·μ΄λ΄λ©΄μ λκ° λ¬Έμ μΈμ§ νμ
ν΄ λκ°λ κ±°μ£ ! 
4κ°μ μ’μμ