【问题标题】:How to make textblock blink|flash in C# for Windows Phone 8.1?如何在 C# for Windows Phone 8.1 中使文本块闪烁|闪烁?
【发布时间】:2014-11-28 23:37:01
【问题描述】:

我有一个页面 MainPage.xaml,它有一个文本框和一个用于 page1.xaml 转换的按钮,在我的页面 mainpage.cs 中我有一个方法:

private void Button_Click(object sender, RoutedEventArgs e)
{
    string newUrl = "/Page1.xaml?text=" + textoInput.Text;
    NavigationService.Navigate(new Uri(newUrl, UriKind.Relative));
}

在我的 Page1.xaml 中,我有一个文本块,它将是放置在 MainPage.xaml 文本框中的文本。 在我的 Page1.cs 我有一个方法:

string textBoxValue = "";
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    //Retrieve the value passed during page navigation
    NavigationContext.QueryString.TryGetValue("text", out textBoxValue);
    textBlockTexto.Text = textBoxValue;     
}

我的问题是如何让我的文本块 (text.BlockTexto.Text) 无限闪烁

谢谢

【问题讨论】:

    标签: c# xaml windows-phone-8


    【解决方案1】:

    您可以将StoryboradColorAnimation 一起使用。这里是MSDN sample

    StackPanel 更改为TextBox,它将为您设置动画背景。这是一个带有动画的 TextBox 示例:

    <TextBox TextBox_Tap="Textbox_Tapped" Text="MyText">
        <TextBox.Resources>
            <Storyboard x:Name="myStoryboard">
            <!-- Animate the background color of the canvas from red to green over 4 seconds. -->
                <ColorAnimation Storyboard.TargetName="mySolidColorBrush"
                    Storyboard.TargetProperty="Color"
                    From="Red" To="Green" Duration="0:0:4" />
            </Storyboard>
        </TextBox.Resources>
        <TextBox.Background>
            <SolidColorBrush x:Name="mySolidColorBrush" Color="Red" />
        </TextBox.Background>
    </StackPanel>
    

    如何调用动画:

    // When the user taps the textbox, the animation begins.
    private void TextBox_Tap(object sender, System.Windows.Input.GestureEventArgs e){
        myStoryboard.Begin();
    }
    

    我不建议您无限循环动画,因为这不符合设计准则,并且由于移动设备的 GPU/CPU 负载过高而消耗电池。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-30
      • 2017-03-08
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 2022-10-17
      相关资源
      最近更新 更多