Domanda

Ho questa funzionalità di goto nel mio datagrid.Questa funzionalità vorrei tenere fuori dal mio mirino e fuori dal codice dietro, quindi il seguente allegato potrebbe essere perfetto, tuttavia ...

L'utente inserisce un numero di linea (elemento), quindi quando l'utente fa clic su GoroButton, porta l'oggetto.

<Grid>
    <TextBox x:Name="GotoTextbox"  Text="{Binding GotoLineNumber, UpdateSourceTrigger=PropertyChanged}" />
    <Button Name="GotoButton" >
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <helpers:TargetedTriggerActionGotoButton TargetObject="{Binding ElementName=GenericDataGrid}"  />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Button>
</Grid>
.

Ecco la classe TargedTrigeration.

public class TargetedTriggerActionGotoButton : TargetedTriggerAction<DataGrid>
{
    protected override void Invoke(object parameter)
    {
        this.Target.SelectedGridItem = GotoLineNumber - 1;
        this.Target.SelectedGridIndex = GotoLineNumber.GetValueOrDefault() - 1;
    }
}
.

Vorrei in qualche modo passare il testo da GoTotextBox, c'è qualche legame che posso fare?.Come potrei ottenere questo?

È stato utile?

Soluzione

Come abbiamo parlato nei commenti
Per consentire il passaggio dei parametri, si dovrebbe implementare ulteriore proprietà nel TargetedTriggerAction

public class TargetedTriggerActionGotoButton : TargetedTriggerAction<DataGrid>
{
    protected override void Invoke()
    {
        this.Target.SelectedGridItem = GotoLineNumber - 1;
        this.Target.SelectedGridIndex = GotoLineNumber.GetValueOrDefault() - 1;
    }
    //property used as parameter
    public object Parameter {get;set;}
}
.

e poi nel tuo xaml

<Grid>
<TextBox x:Name="GotoTextbox"  Text="{Binding GotoLineNumber, UpdateSourceTrigger=PropertyChanged}" />
<Button Name="GotoButton" >
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <helpers:TargetedTriggerActionGotoButton TargetObject="{Binding ElementName=GenericDataGrid}" Parameter="{Binding ElementName="/*desiredName*/",Path="/*neededValue*/"}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top