如何在滑块值更改时使 TextBlock.Text = Slider.Value

发布于 2025-01-01 06:17:48 字数 701 浏览 3 评论 0原文

我已经尝试过了,

   If Slider1.Value = 1 Then
        TextBlock1.Text = "1"
    End If
    If Slider1.Value = 2 Then
        TextBlock1.Text = "2"
    End If
    If Slider1.Value = 3 Then
        TextBlock1.Text = "3"
    End If
    If Slider1.Value = 4 Then
        TextBlock1.Text = "4"
    End If
    If Slider1.Value = 5 Then
        TextBlock1.Text = "5"
    End If

实际上我遇到了一些错误,特别是当我有

    If Slider1.Value = 1 Then
    TextBlock1.Text = "1"
    End If

代码时,因为程序运行时它已经是值 1 了。我是 WPF 新手,真的不知道在这里要做什么,所以请您向我展示或提供有关如何完成的代码示例,谢谢。

而且我已经使用表达混合 4 几天了,我知道如何创建模板并在鼠标悬停时为淡入淡出动画以及按钮的内容,但如果用户单击按钮,我将如何为单独的图片框或图像制作动画淡入或淡出,请给我一个例子,谢谢大家:)。

I've tried this

   If Slider1.Value = 1 Then
        TextBlock1.Text = "1"
    End If
    If Slider1.Value = 2 Then
        TextBlock1.Text = "2"
    End If
    If Slider1.Value = 3 Then
        TextBlock1.Text = "3"
    End If
    If Slider1.Value = 4 Then
        TextBlock1.Text = "4"
    End If
    If Slider1.Value = 5 Then
        TextBlock1.Text = "5"
    End If

I actually get a couple of errors with this, especially when i have the

    If Slider1.Value = 1 Then
    TextBlock1.Text = "1"
    End If

code because it's already on value 1 when the program runs. I'm new to WPF and don't really know what to do here so i you could please show me or provide a code sample on how it's done thanks.

and also i have been using expression blend 4 for a couple of days and i know how to create a template and animate fades on mouse over and stuff for a button but say if the user clicks a button how would i animate a separate picturebox or image to fade in or fade out could you please provide me an example thankyou everyone :).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与风相奔跑 2025-01-08 06:17:48

您不需要在代码隐藏中执行此操作,只需绑定到 XAML 中的值,如果您想以某种方式修改该值,请使用 ValueConverter。

请参阅 http://msdn.microsoft.com/en- us/library/system.windows.data.ivalueconverter.aspx

  <Slider x:Name="mySlider"/>
  <TextBox x:Name="myTextBox" Text="{Binding ElementName=mySlider,Path=Value}"/>

否则,如果您确实想在 CodeBehind 中执行此操作,请使用 ValueChangedEvent:

XAML:

  <Slider x:Name="mySlider" ValueChanged="mySlider_ValueChanged"/>

代码隐藏

Private Sub mySlider_ValueChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Double))
    myTextBox.Text = e.NewValue.ToString()
End Sub

You don't need to do this in Codebehind just bind to your value in XAML and if you want to modify that value somehow, then use a ValueConverter.

see http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx

  <Slider x:Name="mySlider"/>
  <TextBox x:Name="myTextBox" Text="{Binding ElementName=mySlider,Path=Value}"/>

Otherwise if you definitely want to do it in CodeBehind use the ValueChangedEvent:

XAML:

  <Slider x:Name="mySlider" ValueChanged="mySlider_ValueChanged"/>

CodeBehind

Private Sub mySlider_ValueChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Double))
    myTextBox.Text = e.NewValue.ToString()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文