CommunityToolkit.Mvvm RelayCommand Attribute ์‚ฌ์šฉ๋ฐฉ๋ฒ•

์ผ๋ฐ˜์ ์œผ๋กœ RelayCommand๋Š” ICommand ํ”„๋กœํผํ‹ฐ๋ฅผ ์„ ์–ธํ•˜์—ฌ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ž…๋‹ˆ๋‹ค.

public ICommand SaveCommand { get; init }

public MainViewModel()
{
    SaveCommand = new RelayCommand<string>(Save);
}

private void Save(string value)
{

}

๊ทธ๋ฆฌ๊ณ  CommunityToolkit.Mvvm ํŒจํ‚ค์ง€์—์„œ๋Š” Attribute๋ฅผ ํ†ตํ•ด ์กฐ๊ธˆ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

[RelayCommand]
private void Save(string value)
{

}

๋ณด์‹œ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ RelayCommand Attribute๋ฅผ ์„ ์–ธํ•˜๋ฉด ๋ณ„๋„์˜ ํ”„๋กœํผํ‹ฐ์™€ RelayCommand ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ์—†์ด๋„ ๋ฐ”๋กœ ๋ฉ”์„œ๋“œ๋ฅผ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์–ด๋– ํ•œ ์ถ”๊ฐ€์ ์ธ ์†Œ์Šค์ฝ”๋“œ ์—†์ด๋„ ๋ง์ด์ฃ .

Xaml์—์„œ๋Š” ๊ทธ์ € SaveCommand๋ฅผ ๋ฐ”์ธ๋”ฉ ํ•ด์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
(๋‹จ ๋ฉ”์„œ๋“œ์— Command ๋‹จ์–ด๋ฅผ ๋ฐ˜๋“œ์‹œ ๋ถ™์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.)

<Button Command="{Binding SaveCommand}"/>

์ด๋ ‡๊ฒŒ ํ•˜์—ฌ CommunityToolkit.Mvvm์„ ํ†ตํ•œ RelayCommand Attribute ์‚ฌ์šฉ ๋ฐฉ์‹์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
:smile:

์ข‹์•„์š” 10

์ข‹์€ ํŒ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
์™œ ์ €๋Š” Attribute๊ฐ€ ์•ˆ ๋˜์ง€ ํ•ด์„œ ๋ดค๋”๋‹ˆ,
Community.Toolkit.Mvvm์ด ์•„๋‹ˆ๋ผ
Microsoft.Toolkit.Mvvm ์ด์—ˆ๋”๊ตฐ์š” ( ๊ตฌ ๋ฒ„์ „ , Obsolete ).
ํŒจํ‚ค์ง€ ๊ต์ฒดํ•˜๊ณ  ๋ณด๋‹ˆ ์ž˜ ๋˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋‹จ, ์ž๋™ ์ƒ์„ฑ๋œ partial Class๋•Œ๋ฌธ์— partial ์„ ์–ธ์„ ๋‹ค์‹œ ์ถ”๊ฐ€ ํ•ด์ค˜์•ผ ํ•˜๋„ค์š” ใ… 
[โ€ฆ].g.cs ํŒŒ์ผ์ด ์ƒ์„ฑ๋˜๋Š”๊ฑธ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค.

์ข‹์•„์š” 2

@suwoo ์•— ๋„์›€์ด ๋˜์…จ๋‹ค๋‹ˆ ๋‹คํ–‰์ž…๋‹ˆ๋‹ค!!

์ข‹์•„์š” 2

๊ตฌ๋ฒ„์ „(Microsoft.Toolki)์—์„œ๋Š” [ICommand] ๋กœ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค๋งŒ
(๊ตฌ๋ฒ„์ „์—์„œ๋„ partial ์€ ํ•„์ˆ˜!)

๊ตฌ๋ฒ„์ „์—์„œ๋Š” ๋ญ”๊ฐ€ ์ดํ•ดํ•  ์ˆ˜ ์—†๋Š” ๋ฌธ์ œ๊ฐ€ ์ค„์ค„ ๋–จ์–ด์ ธ์„œ
๊ฒฐ๊ตญ Community.Toolkit ์œผ๋กœ ๊ฐˆ์•„ํƒ”์Šด๋‹ค.

Community.Toolkit ์œผ๋ฃจ ๋Œ€๋™๋‹จ๊ฒฐ! ใ…‹ใ……ใ…‹

์ข‹์•„์š” 3

Community.Toolkit.Core, Community.Toolkit.Maui ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
ํ˜ผ๋™ํ•˜์‹œ๋Š” ์ผ ์—†๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค. (Community.Toolkit.Maui ๊ธฐ๋Šฅ์„ Community.Toolkit.Mvvm์—์„œํ•˜๋Š” ์ค„ ์•Œ๊ณ โ€ฆ)



[RelayCommand]
private async Task OnSaveAsync(string value)

// examplePage.xaml
<Button Command="{Binding = SaveCommand}"

[RelayCommand]๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ”์ธ๋”ฉ ํ•  ๋•Œ ์ ‘๋‘์‚ฌ On, ์ ‘๋ฏธ์‚ฌ Async๋Š” ์ž๋™์œผ๋กœ ๊ฑธ๋Ÿฌ์ค๋‹ˆ๋‹ค.
(<Button Command="{Binding = OnSaveAsyncCommand}"๋กœ ๋ฐ”์ธ๋”ฉ ํ•ด์„œ ์‹คํŒจํ•œ ๊ฒฝํ—˜์ด ์žˆ๋„ค์š”)


์ฐธ์กฐ ๋ฌธ์„œ - RelayCommand attribute

์ข‹์•„์š” 5

๋งž๋‹ค, [ICommand]๋ฅผ ๊นœ๋นกํ–ˆ๊ตฐ์š”? ใ…Žใ…Žใ…Žใ…Ž
๊ทธ๋ƒฅ ์ตœ์‹ ๋ฒ„์ „์œผ๋กœ ๋ฐ”๊ฟ”๋ฒ„๋ฆฌ๋ฉด์„œ, ๊ทธ๋ƒฅ ์•„๋ฌด๋ž˜๋„ ๊ทธ๋งŒ์ธ ๋ฌธ์ œ๊ฐ€ ๋˜์–ด๋ฒ„๋ ธ๋„ค์š” ใ… ใ… 
๊ทธ๋ž˜๋„ ์ •๋ง ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

์ข‹์•„์š” 1

On ํ‚ค์›Œ๋“œ๋„ ๊ฑธ๋Ÿฌ์ค„ ์ค„์€ ๋ชฐ๋ž๋„ค์š”, ์—์ž‡ ๊ทธ๋Ÿฌ๋ฉด ๊ตณ์ด ๋ฉ”์„œ๋“œ ์ด๋ฆ„ ๋ฐ”๊ฟ€ ํ•„์š” ์—†์—ˆ๋Š”๋ฐ ใ… ใ… 

์ข‹์•„์š” 3

VS2019์—์„œ Community.Toolkit.Mvvm์˜ Attribute ์ฝ”๋“œ ์ž๋™์ƒ์„ฑ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—†๋‚˜์š”? ใ… ใ… 

์ข‹์•„์š” 1