i want selected gridview row when i changed text in texyBox txtModify.
The easy way is using xaml Behaviors nuget to detect current TextChanged event and if it was triggered then call ChangePropertyAction
to update current gridView_goods SelectedItem property and pass current datacontext as parameter, please refer to the following code.
<TextBox
x:Name="txtModify"
Height="Auto"
AcceptsReturn="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Auto"
Text="{Binding txtModify, Mode=TwoWay}"
TextChanged="txtModify_TextChanged"
TextWrapping="Wrap">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="TextChanged">
<Core:ChangePropertyAction
PropertyName="SelectedItem"
TargetObject="{Binding ElementName=gridView_goods}"
Value="{Binding}" />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
For multiple selectitem, you need to use InvokeCommandAction to call the command in the code behind and insert current datacontext into gridview selecteditems
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var goods = new List<Good>() {
new Good(){TxtOriginal="text1",Uri="http-text1" },
new Good(){TxtOriginal="text2",Uri="http-text1" },
new Good(){TxtOriginal="text3",Uri="http-text1" },
new Good(){TxtOriginal="text4",Uri="http-text1" }
};
gridView_goods.ItemsSource = goods;
}
public ICommand GetSelectItem
{
get
{
return new CommadEventHandler<Good>((s) => {
gridView_goods.SelectedItems.Add(s);
});
}
}
Xaml
<TextBox
x:Name="txtModify"
Height="Auto"
AcceptsReturn="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Auto"
Text="{Binding txtModify, Mode=TwoWay}"
TextChanged="txtModify_TextChanged"
TextWrapping="Wrap">
<Interactivity:Interaction.Behaviors>
<Core:EventTriggerBehavior EventName="TextChanged">
<Core:InvokeCommandAction Command="{Binding DataContext.GetSelectItem, ElementName=gridView_goods}" CommandParameter="{Binding}" />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
Thanks
Nico Zhu