IValueConverter์— MarkupExtension ๋”ํ•˜๊ธฐ

์•ˆ๋…•ํ•˜์„ธ์š”. :smile:

WPF Converter ๊ด€๋ จ ๊ฐ„๋‹จํ•œ ํŒ์ž…๋‹ˆ๋‹ค.

MarkupExtension

WPF Converter๋ฅผ ๋งŒ๋“ค ๋•Œ IValueConverter์™€ ์ด๊ฒƒ์„ ํ•จ๊ป˜ ์ƒ์†๋ฐ›์•„ ๋งŒ๋“ค๊ฒŒ ๋˜๋ฉด
Xaml์—์„œ Converter๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ Resource Key๋ฅผ ๋”ฐ๋กœ ๋งŒ๋“ค์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.

BooleanToVisibilityConverter.cs

public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter
{
	public object Convert(object value, Type targetType,
		object parameter, CultureInfo culture)
	{
		return value.Equals(true) ? Visibility.Visible : Visibility.Collapsed;
	}

	public object ConvertBack(object value, Type targetType,
		object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}

	public override object ProvideValue(IServiceProvider serviceProvider)
	{
		return this;
	}
}

Xaml์—์„œ ์‚ฌ์šฉํ•  ๋•Œ

<Border Visibility"="{Binding IsVisible, FallbackValue=Collapsed, 
                              Converter ={cnvts:BooleanToVisibilityConverter}}"/>

์ €๋„ ์ตœ๊ทผ์— ์•Œ๊ณ  ์‚ฌ์šฉํ•ด๋ณด๊ณ  ์žˆ๋Š”๋ฐ์š”.
ํ˜น์‹œ ๋ฌธ์ œ๋˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๊ฑฐ๋‚˜ ์›๋ž˜ ์‚ฌ์šฉํ•˜๊ณ  ๊ณ„์‹  ๋ถ„๋“ค์˜ ์˜๊ฒฌ๋„ ๋“ฃ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. :smile:

(๊ทธ๋ฆฌ๊ณ  ํ˜น์‹œ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ์„ ๊ฒฝ์šฐ ์งˆ๋ฌธ ๊ฒŒ์‹œํŒ์œผ๋กœ ์˜ฎ๊ธธ ์ˆ˜๋„ ์žˆ์–ด์š”!)

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

์ข‹์•„์š” 4

์˜คโ€ฆ!! ์ด๊ฒƒ์€ ์ •๋ง ํŠน๊ธ‰ ๊ฟ€์ด๊ตฐ์š” ใ…Žใ…Žใ…Ž ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค james๋‹˜!

์ข‹์•„์š” 1

๋จธ๋ฆฟ์†์œผ๋ก  "๊ฐ€๋Šฅํ•˜๊ฒ ์ง€?"๋ผ๊ณ  ์ƒ๊ฐํ–ˆ์—ˆ์œผ๋‚˜ ์‹ค์ œ๋กœ ์‹คํ—˜ํ•œ ์ ์ด ์—†์–ด ์ฐธ ๊ถ๊ธˆํ–ˆ๋˜ ๋ถ€๋ถ„์ธ๋ฐ ์‹คํ—˜ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :slight_smile:

์ข‹์•„์š” 2