I have a control defined in Silverlight as follows:
<HyperlinkButton x:Name="testHyperlink" Content="Test" FontWeight="Bold" Click="testHyperlink_Click">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction PropertyName="Visibility" TargetName="panel1"
Value="Collapsed开发者_运维问答" />
<ei:ChangePropertyAction PropertyName="Visibility" TargetName="panel2"
Value="Visible" />
</i:EventTrigger>
<i:EventTrigger>
<ei:ChangePropertyAction PropertyName="Visibility" TargetName="panel1"
Value="Visible" />
<ei:ChangePropertyAction PropertyName="Visibility" TargetName="panel2"
Value="Collapsed" />
</i:EventTrigger>
</i:Interaction.Triggers>
</HyperlinkButton>
This hyperlink is part of a DataTemplate. That is the reason I'm using the triggers. When someone clicks the HyperlinkButton, an asynchronous process is fired. When the process has completed, I want to execute the second trigger. Essentially, I'm flipping the visibility of some content.
My question is, when my event is finished, how do I fire the second EventTrigger associated with the HyperlinkButton?
It's incorrect using of Interactivity EventTriggers. Answering directly your question, you can do next (I'm writting that only because I coudn't write that it's impossible, but I'm ashamed for this solution):
create own action with public Invoke
public class MyChangePropertyAction: ChangePropertyAction
{
public new void Invoke(object parameter)
{
base.Invoke(parameter);
}
}
Use it instead Interactivity ChangePropertyAction. Now you can get invoke action directly from code behind:
((MyChangePropertyAction)Interaction.GetTriggers(testHyperlink)[1]).Invoke(parameter);
But, I believe that you can simply use MVVM approach and do next:
- create bool property IsBusy with property changed notification in view model;
- bind it to your "panel1" Visibility property via BooleanToVisibility converter;
- bind command DoServiceCall from view model to "testHyperlink" Command property;
- and in view model make service calls and change IsBusy property to true or false depending on should you display panel or not.
Good luck
精彩评论