0

I have an OK button that accepts data input, but the user can change some data and press it again. Each press saving a particular configuration.

I want the selection on the OK button to go away, so that the user knows it's been accepted.

Ideally, I would like a pure WPF solution.

Update: some code

<ControlTemplate x:Key="MapCutIconsTemplate">
    <DockPanel DockPanel.Dock="Right">
        <controls:ImageButton Style="{DynamicResource ButtonStyle}"
                              Content="OK"
                              DockPanel.Dock="Top"
                              Command="{Binding AcceptPositionCommand}" 
                              Source="{DynamicResource OkIcon}" 
                              Background="{DynamicResource BackgroundColour}"/>

        <controls:ImageButton Style="{DynamicResource ButtonStyle}"
                              Content="Back"
                              DockPanel.Dock="Top"
                              Command="{Binding BackCommand}" 
                              Source="{DynamicResource BackIcon}" 
                              Background="{DynamicResource BackgroundColour}"/>

    </DockPanel>
</ControlTemplate>

I would like to move selection from OK button to Back button, once OK button is clicked.

Update2: getting closer

CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self}}"

this gets me the button that has been pressed, passed in as a parameter to the Command function. What I really need is the other button object.

Solution:

CommandParameter="{Binding ElementName=CutBack}"

proposed by @VS1.

ahnkle
  • 467
  • 6
  • 17
  • Can you be more clear, give a code example, or what you tried at least please – AymenDaoudi Jul 25 '14 at 16:10
  • A `button` accepting data input? – afaolek Jul 25 '14 at 16:16
  • You are looking for CanExecute on your ICommand for the button in your ViewModel (This will be your 'pure' WPF (MVVM) approach) – Krishna Jul 25 '14 at 16:20
  • 1
    You should read the [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) page from the Help Center. – Sheridan Jul 25 '14 at 16:24
  • Krishna: I am indeed using ICommand, but I don't want to disable the button after it's clicked, just move focus to another button. – ahnkle Jul 28 '14 at 09:15
  • Do you mean that you want to move focus to another button once it has been pressed? – Alessandro Rossi Jul 28 '14 at 10:29
  • possible duplicate of [How to move focus in WPF?](http://stackoverflow.com/questions/15587649/how-to-move-focus-in-wpf) – Alessandro Rossi Jul 28 '14 at 10:48
  • See here http://stackoverflow.com/questions/15587649/how-to-move-focus-in-wpf – Alessandro Rossi Jul 28 '14 at 10:49
  • @AlessandroRossi That question doesn't really relate to templates. See update2, in my question. – ahnkle Jul 28 '14 at 11:38
  • Can you try to change: `CommandParameter="{Binding ElementName=backButton}"` and give `Name="backButton"` for your backbutton and then in Command OnExecute for AcceptPosition button, do: `(parameter as button).Focus();` – S2S2 Jul 28 '14 at 11:55
  • @VS1 This works for me. Propose it as an answer and I'll mark this as answered. – ahnkle Jul 28 '14 at 13:08

1 Answers1

0

Please change your xaml with below code:

<ControlTemplate x:Key="MapCutIconsTemplate">
    <DockPanel DockPanel.Dock="Right">
        <controls:ImageButton Name="acceptButton" 
                          Style="{DynamicResource ButtonStyle}"
                          Content="OK"
                          DockPanel.Dock="Top"
                          Command="{Binding AcceptPositionCommand}" 
                          CommandParameter="{Binding ElementName=backButton}" 
                          Source="{DynamicResource OkIcon}" 
                          Background="{DynamicResource BackgroundColour}"/>

        <controls:ImageButton Name="backButton" 
                          Style="{DynamicResource ButtonStyle}"
                          Content="Back"
                          DockPanel.Dock="Top"
                          Command="{Binding BackCommand}" 
                          Source="{DynamicResource BackIcon}" 
                          Background="{DynamicResource BackgroundColour}"/>

    </DockPanel>
</ControlTemplate>

And, your ViewModel's AcceptPositionCommand.OnExecute to include below line:

(parameter as Button).Focus(); //Will move focus to Back Button
S2S2
  • 8,322
  • 5
  • 37
  • 65