sprocket12
sprocket12

Reputation: 5488

How to target a different control with a trigger?

How can I click the button and then it set the Value of txtNoOfVehicles to NULL or ""?

<dxg:GridControl ItemsSource="{Binding ShiftEntries}">  
    <dxg:GridControl.Columns>
        <dxg:GridColumn Header="No. of Vehicles">
            <dxg:GridColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel>
                        <dxe:TextEdit x:Name="txtNoOfVehicles" Text="{Binding RowData.Row.NoOfVehicles}" Mask="\d{1,4}" MaskType="RegEx" NullText="Infinity" NullValue="{x:Null}" AllowNullInput="True" ShowError="False" />
                        <Button Content="Infinity" Margin="3" />
                    </StackPanel>
                </DataTemplate>
            </dxg:GridColumn.CellTemplate>
        </dxg:GridColumn>
    </dxg:GridControl.Columns>
</dxg:GridControl>

I researched style/data/event triggers, but all the examples I saw targeted the same control that had the trigger applied. I would like the trigger on the click of the button, and the target to be the Text property of the TextEdit.

I Tried:

<Button Content="Infinity" Margin="3">
    <Button.Style TargetType="{x:Type Button}">
        <Style.Triggers>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="txtNoOfVehicles" Property="dxe:TextEdit.Text" Value="{x:Null}" />
            </Trigger>
        </Style.Triggers>
    </Button.Style>
</Button>

Upvotes: 0

Views: 454

Answers (1)

TYY
TYY

Reputation: 2716

To answer your question you can do something like this

<StackPanel>
    <TextBlock Name="Block"  Text="Test"  />
    <Button Name="btn">
         <Button.Triggers>
             <EventTrigger SourceName="btn" RoutedEvent="Button.Click">
                  <BeginStoryboard>
                       <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Block"
                                                                   Storyboard.TargetProperty="Text"
                                                                   >
                                <DiscreteObjectKeyFrame Value=""></DiscreteObjectKeyFrame>
                           </ObjectAnimationUsingKeyFrames>
                      </Storyboard>
                 </BeginStoryboard>
             </EventTrigger>
       </Button.Triggers>
    </Button>
 </StackPanel>

Upvotes: 1

Related Questions