user3523890
user3523890

Reputation: 49

XAML Get data from binded elements

I have this XAML code:

<ListView Name="ListBoxWithNews" ItemsSource="{Binding News}" Grid.Row="1" Grid.Column="1"  Grid.RowSpan="2" Grid.ColumnSpan="2">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding imageURL}" Width="75" Height="75" />
                <StackPanel>
                    <TextBox Text="{Binding Title}" Width="200" />
                    <TextBox Text="{Binding Body}" Width="200" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

The controls are binded using the MVVM pattern. The user can change the content of the two text boxes. Is there a possible way to get the updated text from these text boxes at some point when I need them?

Upvotes: 0

Views: 83

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222522

Your ViewModel should implement INotifyPropertyChanged and Use TwoWay Binding as below

<ListView Name="ListBoxWithNews" ItemsSource="{Binding News,Mode=TwoWay}" Grid.Row="1" Grid.Column="1"  Grid.RowSpan="2" Grid.ColumnSpan="2">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding imageURL,Mode=TwoWay}" Width="75" Height="75" />
                <StackPanel>
                    <TextBox Text="{Binding Title,Mode=TwoWay}" Width="200" />
                    <TextBox Text="{Binding Body,Mode=TwoWay}" Width="200" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Upvotes: 1

Related Questions