I'm writing adding,updating and deleting operations for <ListView> in WPF using by MVVM.
My question is that How can I give two binding for the same <TextBox>(one of these is for adding element to <ListView>and the other is for updating(selectedItem of <ListView>))
What I have tried:
When I write binding for adding it works successfully.And also When I write binding for updating the selected row is written to <TextBox>.But I need these work together.I tried <MultiBinding> but result weren't be successfull.Hope your helps..
For adding:
<TextBox Grid.Column="1" x:Name="txtSurname" Text="{Binding Path=Student.Surname, Mode=TwoWay}">
<TextBox.Effect>
<DropShadowEffect ShadowDepth="3" Color="#75B07A"/>
</TextBox.Effect>
</TextBox>-->
For updating:
<TextBox Grid.Column="1" x:Name="txtSurname" Text="{Binding ElementName=lstStuds, Path=SelectedItem.Surname}">
<TextBox.Effect>
<DropShadowEffect ShadowDepth="3" Color="#75B07A"/>
</TextBox.Effect>
</TextBox>
This is my <listview> :
<ListView x:Name="lstStuds" ItemsSource="{Binding Path=Students}" SelectedItem="{Binding SelectedStudent}" Grid.Column="1" Grid.Row="1" Grid.RowSpan="3" Margin="0,10,20,20" FontSize="16">
<ListView.Effect>
<DropShadowEffect ShadowDepth="3" Color="#75B07A"/>
</ListView.Effect>
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="150"/>
<GridViewColumn Header="Surname" DisplayMemberBinding="{Binding Surname}" Width="150"/>
</GridView>
</ListView.View>
And my buttons:
<Button Content="Add" Command="{Binding AddCommand}" Width="120" Height="auto" FontSize="18" Margin="0 0 0 10">
<Button.Effect>
<DropShadowEffect ShadowDepth="3" Color="#75B07A"/>
</Button.Effect>
</Button>
<Button Content="Update" Command="{Binding EditCommand}" CommandParameter="{Binding ElementName=lstStuds, Path=SelectedItem}" Width="120" Height="auto" FontSize="18" Margin="0 0 0 10">
<Button.Effect>
<DropShadowEffect ShadowDepth="3" Color="#75B07A"/>
</Button.Effect>
</Button>