c# - WPF DoubleUpDown 命令绑定(bind)到上下按钮

标签 c# .net wpf

  <TextBox Text="{Binding Path=ScalingFactor, Mode=TwoWay, StringFormat=F5}" Grid.Row="0" Grid.Column="0"  HorizontalAlignment="Left" Width="150" behaviors:TextBoxBehavior.SelectAllTextOnFocus="True" behaviors:InputBindingsManager.SourceProperty="TextBox.Text"/>
  <Button  Command="{Binding MultiplyCommand}" Grid.Row="0" Grid.Column="1"
           HorizontalAlignment="Center"
           Margin="{StaticResource MarginItemLeft}">
           <Image Source="/Themes;component/BaseTheme/Images/Add.png" Stretch="None" />
  </Button>
  <Button  Command="{Binding DivideCommand}" Grid.Row="0" Grid.Column="2"
                         HorizontalAlignment="Center"
                         Margin="{StaticResource MarginItemLeft}">
          <Image Source="/Themes;component/BaseTheme/Images/Minus.png" Stretch="None" />
  </Button>

我有一个包含两个命令的文本框,
因为这看起来真的很像 WPF 扩展工具包中的 DoubleUpDown,所以我想用它替换所有这些代码。
但是我找不到任何关于如何绑定(bind)命令的文档?
你能帮我把 multiplyCommand 连接到上键,把 DivideCommand 连接到下键吗?

最佳答案

最好的选择是将您在用户/自定义控件中呈现的 xaml 包装起来(取决于您需要允许的自定义级别),然后为 Min、Max 和 Value 添加依赖属性(以便在使用时允许绑定(bind)) .在 up 和 down 命令的 Execute 方法中,只需根据最小值和最大值验证预期值。

关于c# - WPF DoubleUpDown 命令绑定(bind)到上下按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29132995/

相关文章:

c# - 按位运算评估为长

c# - 删除此 'return' 语句或使其成为条件

C# 是否有一种紧凑的方法来获取二维数组中的多个坐标?

c# - 如何在 C# 中从网络驱动器获取文件所有者?

WPF 使用 CategoryAxis 绘制 ColumnSeries,列之间的边距

c# - 在不同的项目中 Split View View 模型和模型 - 我将 ViewModelLocator 放在哪里

c# - 跨 .NET 版本从应用程序引用 DLL...可能吗?

c# - matlab:在 .net 程序集中使用函数提示

wpf - 在 View 模型中拥有 View 模型是不是很糟糕?

c# - 更改 ListView 中的确切滚动位置