tags:

views:

181

answers:

1

I have a textbox and a button in my form. I enter some text and click on Mouse double it should It should Call the Button Command,CommandParameter. Is this possible?

There is no code behind.

A: 

You could make a Button Template, that internally has a TextBox (maybe with IsHitTestVisible set to false and an outer Grid with Transparent Background). Then you can bind your command directly to this "TextBox-Button".

Edit: Source code:

<Grid>
  <Grid.Resources>
    <Style TargetType="{x:Type Button}">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type Button}">
              <TextBox />
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
  </Grid.Resources>

  <Button Content="Test" />
</Grid>

And invoke the command via Attached Behavior Pattern like described here and here.

Andrej

Andrej
<Window.Resources><Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <TextBox Text="TextBox" TextWrapping="Wrap"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <Button Margin="107,114,96,90" x:Name="button1" IsHitTestVisible="False" Background="Transparent" Style="{DynamicResource ButtonStyle1}"/> </Grid>
sDev
Tried doing this but the TextBox-Button is readonly.
sDev
Try moving the Grid around the TextBox in the Template and setting IsHitTestVisible on the TextBox and not on the Button
Andrej
I just tried it out, put *only* the TextBox in the template without IsHitTestVisible and handle the MouseDoubleClick-Event of the Button - it works :)
Andrej
If you insist on having no code behind, you can use the Attached Behavior Pattern (infos: http://www.bjoernrochel.de/2009/08/19/the-attached-behavior-pattern/) to invoke a Command when doubleclicking
Andrej
Thanks a lot. Attached Behaviour Pattern worked.
sDev
http://eladm.wordpress.com/2009/04/02/attached-behavior/
sDev
If it worked, please mark my answer as accepted ;-)
Andrej
I tried to mark as answer but it says Vote up requires 15 reputation
sDev