<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/