2
XAML에서 메서드 처리기를 할당 할 수 있도록 Func 유형의 종속성 속성을 추가하려는 사용자 정의 컨트롤이 있습니다. 그러나이 경우 XAMLParseException이 발생합니다. 'Func`2'형식에는 공용 TypeConverter 클래스가 없습니다. 내가 도대체 뭘 잘못하고있는 겁니까? Func 용 TypeConverter를 구현해야합니까, 아니면 더 좋은 방법이 있습니까?사용자 정의 컨트롤의 Func 속성
사용자 컨트롤에 Func을 종속성 속성 (을 MyUserControl)
<Window x:Class="FuncTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:FuncTest="clr-namespace:FuncTest"
Title="Window1" Height="300" Width="300">
<Grid>
<FuncTest:MyUserControl MyFunc="SquareHandler" />
</Grid>
</Window>
코드 숨김 :
namespace FuncTest
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
SquareHandler = (arg => arg * arg);
DataContext = this;
}
public Func<int, int> SquareHandler { get; set; }
}
}