[##_1C|1410193552.png|width="228" height="208" alt="사용자 삽입 이미지"|_##]
Windows1 > canvas > rectange 의 구조에서,
Rectange Width 를 Canvas Width 의 90% 로 Binding 하는 예제
IValueConverter 를 사용.
[CODE C#]
namespace WpfApplication2.Converter
{
using System;
using System.Windows.Data;
public class PercentageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return System.Convert.ToDouble(value) * System.Convert.ToDouble(parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
[/CODE]
[CODE XML]
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Converter="clr-namespace:WpfApplication2.Converter"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Converter:PercentageConverter x:Key="PercentageConverter" />
</Window.Resources>
<Canvas x:Name="canvas">
<Rectangle Width="{Binding Converter={StaticResource PercentageConverter}, ElementName=canvas, Path=ActualWidth, ConverterParameter=0.9}" Height="100" Fill="Chocolate"></Rectangle>
</Canvas>
</Window>
[/CODE]
[##_1C|8345409908.zip|style="width: 90px; height: 30px; border: 2px outset #796; background-color: #efd; background-repeat: no-repeat; background-position: center center; background-image: url('/tc/image/extension/unknown.gif')"|_##]
1 Articles, Search for '2009/12'
일 이야기2009/12/06 02:26
Tags WPF

