뷰 모델의 속성에 연결된 연결된 속성을 사용하는 데 중점을두고있는 TextBox가 있습니다. 연결된 속성은 "UIElement.Focus()"를 호출하여 포커스를 설정합니다. 문제는 "GotFocus"이벤트가 발생하지 않는 방식으로 TextBox가 포커스를받을 때입니다. Caliburn.Micro의 Message.Attach를 사용하여 이벤트를 처리합니다. 어떤 아이디어?caliburn에 대한 도움이 필요하십니까? TextBox가 포커스를 얻었을 때의 응답
다음은 TextBox입니다.
<TextBox x:Name="Test"
Grid.Column="0"
Text="{Binding Test, Converter={StaticResource TestToStringConverter}}"
AttachedProperties:FocusExtension.IsFocused="{Binding IsTestFocused}"
cal:Message.Attach="[Event GotFocus] = [Action OnGotFocus($eventargs)]; />
여기에 첨부 된 속성 (SO에 있음)이 있습니다.
public static class FocusExtension
{
public static bool GetIsFocused(DependencyObject obj)
{
return (bool) obj.GetValue(IsFocusedProperty);
}
public static void SetIsFocused(DependencyObject obj, bool value)
{
obj.SetValue(IsFocusedProperty, value);
}
public static readonly DependencyProperty IsFocusedProperty =
DependencyProperty.RegisterAttached("IsFocused", typeof (bool), typeof (FocusExtension),
new UIPropertyMetadata(false, OnIsFocusedPropertyChanged));
private static void OnIsFocusedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var uie = (UIElement)d;
if ((bool)e.NewValue)
{
uie.Focus();
}
}
}
첨부 된 속성에 대한 코드를 제공 할 수 있습니까? – devdigital
첨부 된 속성 코드를 추가하도록 업데이트되었습니다. – Snarfblatt