Tokhi
April 29, 2025, 4:23am
1
์๋
ํ์ธ์. ํ๋์ Window์ UserControl์ด ๋๊ฐ ์ผ๋ UserControl๋ผ๋ฆฌ ์ ๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ์์ผ ํ๋๋ฐ ๊ณ์ ์๋์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํฉ๋๋ค.
OperateRate๊ฐ ์์ ๋ฌธ์ UserControlA์
๋๋ค.
๊ฐ์ ๊ฐ์ ๋ก ์ ์ฉํ๋ฉด ์ ์์ ์ผ๋ก ๊ฐ์ด ๋์ด๊ฐ๋๋ฐ ์ด๋ฅผ ๋ฐ์ธ๋ฉํด์ ๋๊ธธ ์ ๊ฐ ์๋๊ฑด์ง์??
UserControlA - behind
public UserControlA : UserControl
{
public static readonly StyledProperty<int> stopSecondsProperty = AvaloniaProperty.Register<UserControlA, int>(nameof(StopSeconds), 0, defaultBindingMode: BindingMode.TwoWay);
public int StopSeconds
{
get => GetValue(stopSecondsProperty);
set => SetValue(stopSecondsProperty , value);
}
UserControlB - behind
public UserControlB : UserControl
{
public static readonly StyledProperty<int> stopProperty = AvaloniaProperty.Register<UserControlB, int>(nameof(StopSecond), 0 ,defaultBindingMode: BindingMode.TwoWay );
public int StopSecond
{
get => GetValue(stopProperty);
set => SetValue(stopProperty, value);
}
MainWindow - xml
... ์ค๋ต ..
<controls:UserControlB Name="UserB"/>
<controls:UserControlA StopSeconds="{Binding #UserB.StopSecond}"/>
<!-- ์ ์ ์ ์ปจํธ๋กคA์ ๋ฐ์ธ๋ฉํ๋ฉด ์๋ฌ๊ฐ ๋ฐ์. ๊ฐ์ ๋ฃ์ด์ฃผ๋ฉด ์ ์์ ์ผ๋ก ์๋ , ๋ถ๋ชจWindow์ Element๋ก ์ ๊ทผํด์ ๋ฐ์ธ๋ฉํด๋ ์ด๋ฏธ์ง์ ์๋ฌ๋ฐ์ -->
al6uiz
April 29, 2025, 5:29am
2
์ฌ๋ ค์ฃผ์ ์์ ์ฝ๋๋ ์๋ชป๋ ๋ถ๋ถ์ด ์์ด ๋ณด์ด๋๋ฐ ํน์ ์๋ณธ ์ฝ๋์์ ์ค์ํ์ ๊ฒ ์๋๊น์?
Tokhi
April 29, 2025, 8:01am
3
์๋
ํ์ธ์. ์ ๋ ์๋ณธ์ฝ๋์์ ๋ญ๊ฐ ์๋ชป๋๊ฒ ์๋์ถ์ด ํ๋ก์ ํธ๋ฅผ ์๋ก ์์ฑํ๊ณ ํด๋ดค์ต๋๋ค. ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค ใ
ใ
๋ญ๊ฐ ๋ฌธ์ ์ธ์ง ๋ํต๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
Tokhi
April 29, 2025, 8:27am
4
๋ฐฉ๊ธ ๋ค์ ๋ณด๋ค๊ฐ ํด๊ฒฐํ์ต๋๋ค ใ
ใ
์๋ฌด๊ฒ๋ ์๋๊ฑฐ์ ํ๋ฃจ์ข
์ผ ์ฝ์งํ์ต๋๋ค.
์๋ฐ๋ก๋์ ์์ฒด์ ๋ฌธ์ ์ธ์ง ๋ชจ๋ฅด๊ฒ ์ผ๋ ์๋์ ๊ฐ์ด ๋ฐ๊พธ๋ ์ ์์ ์ผ๋ก ๊ฐ์ด ์ฌ๋ผ์ต๋๋ค.
<controls:UserControlB Name=โUserBโ/>
<controls:UserControlA StopSeconds=โ{Binding #UserB .StopSecond}โ/>
์ด ์๋๋ผ
<controls:UserControlB Name=โUserBโ StopSecond=โ{Binding #UserA .StopSeconds}โ/>
<controls:UserControlA Name=โUserAโ />
1 Like
al6uiz
April 29, 2025, 8:31am
5
StopSeconds StopSecond
axaml์ชฝ์ ๋ ์์ฑ ์ด๋ฆ์ด ๋ค๋ฅธ๋ฐโฆ ํน์ ์ด๊ฒ๋๋ฌธ์ดโฆ์๋์งโฆ
1 Like
Tokhi
April 29, 2025, 9:31am
6
์ ์์ ๋ง ๋๊ณ ์์์ค๋ ์๋๋ค์ ใ
ใ
;;; ๋ค๋ฅธ ์์ธ์ด ์๋๋ด
๋๋ค ใ
ใ
1 Like
al6uiz
April 29, 2025, 9:38am
7
์, ์์ธ์ ์ฐพ์ ๊ฒ ๊ฐ์ต๋๋ค.
์คํํด๋ณด์ง ์๊ณ ์ถ์ธก์ผ๋ก ๋ต๋ณ๋๋ ค ์ฃ์กํฉ๋๋ค.
์ฌ๋ ค์ฃผ์ ์ฝ๋๋ฅผ ๊ทธ๋๋ก ๋ณต๋ถํด๋ณด๋ ์ค๋ฅ๊ฐ ์ฌํ๋์๋๋ฐ์.
WPF์ Dependency Property์ ๋ง์ฐฌ๊ฐ์ง๋ก Avalonia์ Styled Property๋ฅผ ์ ์ํ ๋๋ CLR ์์ฑ ์ด๋ฆ + Property suffix ๊ท์น์ ์ง์ผ์ผ ํฉ๋๋ค.
์ฆ, ์์ฑ ์ด๋ฆ์ ๋ค์๊ณผ ๊ฐ์ ํํ๋ก ์์ฑ๋์ด์ผ ํฉ๋๋ค.
[์์ฑ์ด๋ฆ]Property
๊ด๋ จ ๊ณต์ ๋ฌธ์: Defining Properties | Avalonia Docs
ํ์ฌ UserControlA์์๋ stopSecondsProperty๋ก ์ ์ธํ์
จ๊ณ ,
UserControlB์์๋ stopProperty๋ก ์ ์ธํ์
จ๊ธฐ ๋๋ฌธ์,
UserControlB์ ๊ฒฝ์ฐ ๋ฐ์ธ๋ฉ ๋์ ์์ฑ์ ์ฐพ์ง ๋ชปํ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ๊ฒ์
๋๋ค.
(์ฌ๋ฏธ์๋ ์ ์, stopSecondsProperty์ฒ๋ผ CamelCase๋ก ์์ฑํ ์ด๋ฆ์์๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์๋๋ค๋ ๊ฒ์
๋๋ค.)
์๋์ ๊ฐ์ด ์์ฑ ์ด๋ฆ์ ๋ง์ถฐ์ฃผ์๋ฉด ์ ๋์ํ์๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
public class UserControlA : UserControl
{
public static readonly StyledProperty<int> StopSecondsProperty = AvaloniaProperty.Register<UserControlA, int>(nameof(StopSeconds), 0, defaultBindingMode: BindingMode.TwoWay);
public int StopSeconds
{
get => GetValue(StopSecondsProperty);
set => SetValue(StopSecondsProperty, value);
}
}
public class UserControlB : UserControl
{
public static readonly StyledProperty<int> StopSecondProperty = AvaloniaProperty.Register<UserControlB, int>(nameof(StopSecond), 0, defaultBindingMode: BindingMode.TwoWay);
public int StopSecond
{
get => GetValue(StopSecondProperty);
set => SetValue(StopSecondProperty, value);
}
}
6 Likes
Tokhi
April 30, 2025, 12:15am
8
์!!! ์ ์์ ์ผ๋ก ์ปดํ์ผ๋ฉ๋๋ค ใ
ใ
๋ช
๋ช
๊ท์น์ด ์ค์ํ ์ค์ด์ผ ใ
ใ
์ด์ ํ๋ฃจ๋์ ์ด๊ฑธ ํด๊ฒฐํ๋ ค๊ณ ๋ณ์ง์ ๋ค ํ๋๋ฐ ๋๋ฌด ์์์ํฉ๋๋ค!! ใ
ใ
์ ๋ง ๋๋ฌด๋๋ฌด ๊ฐ์ฌํฉ๋๋ค~!!!
2 Likes