我有一个<Border>
里面有一个<Image>
和一个<Textblock>
,我正在尝试更改 Mouseleftbutton 上的文本块文本,因为在这个点击事件中有一些更冗长的操作,文本块的文本在这个操作完成之前不会改变。
我也试过了Dispatcher.BeginInvoke()
,但没有成功。
这是我的代码:
<Border x:Name="btnReadMe" Grid.Row="0" Style="{StaticResource BorderStyle1}" MouseLeftButtonDown="btnReadMe_MouseLeftButtonDown" MouseLeftButtonUp="btnReadMe_MouseLeftButtonUp" >
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#46c746" Offset="0"/>
<GradientStop Color="#129312" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="/CareFamily.AtHome;component/Resources/read_message-read_it.png" Margin="5,15" >
<Image.RenderTransform>
<ScaleTransform ScaleX="1" ScaleY="1"/>
</Image.RenderTransform>
</Image>
<StackPanel Grid.Column="1" Margin="0,10,0,10" VerticalAlignment="Center">
<TextBlock Name="tbReadToMe" Text="Read to Me" Style="{StaticResource TextBlockStyle1}" Margin="0,0,0,0" />
</StackPanel>
</Grid>
</Border>
SpVoice voice;
private void btnReadMe_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (voice == null)
voice = new SpVoice();
string readMessageState = tbReadToMe.Text;
switch (readMessageState)
{
case "Read to Me":
{
tbReadToMe.Text = "Pause";
break;
}
case "Pause":
{
tbReadToMe.Text = "Resume";
voice.Pause();
break;
}
case "Resume":
{
tbReadToMe.Text = "Pause";
voice.Resume();
break;
}
default:
{
tbReadToMe.Text = "Read to Me";
break;
}
}
if (!string.IsNullOrEmpty(Msg.Subject))
{
voice.Speak(Msg.Subject, SpeechVoiceSpeakFlags.SVSFDefault);
}
if (!string.IsNullOrEmpty(Msg.Body))
{
voice.Speak(Msg.Body, SpeechVoiceSpeakFlags.SVSFDefault); // Length operation
}
}