2015-03-18 123 views
3
<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> 

有兩個命令,
因爲這真的看起來像DoubleUpDown從WPF擴展工具套件我想用它代替所有這些代碼的文本框中。
但是我找不到任何有關如何綁定命令的文檔?
你能幫我連接multiplyCommand到上鍵和DivideCommand到下鍵嗎?WPF DoubleUpDown命令我結合上下按鈕

+0

您需要創建從TextBox派生的自定義控件,然後纔可以修改該控件的ControlTemplate。在控制模板中添加向上和向下按鈕。在自定義控件中,您可以處理可以作爲命令公開的按鍵事件和按鍵事件。 – 2015-03-18 21:54:20

+0

@Ganesh我不想繼承TextBox,我想使用WPF擴展工具包。不創建自定義控件 – Gilad 2015-03-18 22:05:42

+0

您能否提供更多關於您想要做什麼的信息?我很難理解這個問題。你想用這個模板替換WPF的模板嗎? – 2015-03-18 22:32:29

回答

1

最好的選擇是將你在用戶/自定義控件中呈現的xaml(取決於你需要允許的自定義級別)包裝起來,然後爲Min,Max和Value添加依賴項屬性(以允許在使用時綁定)。在上下命令的Execute方法中,只需根據最小值和最大值驗證期望值。

+0

我不明白這是如何用WPF Toolkit UpDown控件替換現有的xaml .. – 2015-03-19 20:42:02