0
Visual Studio 용 Blend를 사용하여 가장 간단한 WPF 응용 프로그램을 만들었습니다.WPF에서 동적으로 GoToState를 사용할 수 없습니다. 뭐가 잘못 되었 니?
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="VisualState">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="textBox">
<EasingColorKeyFrame KeyTime="0" Value="#FFE40404"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="VisualState1">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="textBox">
<EasingColorKeyFrame KeyTime="0" Value="#FF23FF00"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120">
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyUp">
<ei:GoToStateAction StateName="VisualState1"/>
</i:EventTrigger>
<i:EventTrigger EventName="KeyDown">
<ei:GoToStateAction StateName="VisualState"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
: 이것은 내 XAML입니다
public MainWindow()
{
InitializeComponent();
textBox.MouseEnter+=new System.Windows.Input.MouseEventHandler(textBox_MouseEnter);
}
private void textBox_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
// This will be an empty list
var states = VisualStateManager.GetVisualStateGroups(textBox);
// This will be false
bool thisReturnsFalse = VisualStateManager.GoToState(textBox, "VisualState1", true);
}
:
내 문제는 내가 동적 GotoState에이 코드를 사용하지 않을 수 있다는 것입니다 :
나는 하나의 텍스트 상자에 대한 간단한 시각적 상태 그룹을 생성
내 GoToState 호출은 이벤트에서 온 것입니다. XAML의 TextBox에서 VisualStateGroups를 이동해야했지만 다음과 같이 나타납니다. /* 예상대로 1입니다. */ var stateGroups = VisualStateManager.GetVisualStateGroups (textBox); /* 여전히 false입니다. */ bool thisReturnsFalse = VisualStateManager.GoToState (this, "VisualState1", false);/* 또한 내 KeyUp, KeyDown이 작동하지 않습니다. */ – profimedica
@profimedica는 질문에 XAML이 표시하지 않으므로 이러한 변경 사항을 반영하도록 XAML을 업데이트합니다. –
@profimedica GoToState 대신 GoToElementState 호출 –