2016-05-02 14 views
1

ListView.ItemTemplateを持つListViewは重要です(ListViewはグリッドの一部です)。私はminumumのために、ここでそれを取り除くことができます:UWPデータバインドでコンテンツにアクセスするListView

<ListView x:Name="lstFotos" Grid.Row="2" Grid.Column="1" Height="auto" Tapped="imageControl_Tapped" > 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <Grid IsTapEnabled="True" > 
       <Grid.RowDefinitions> 
        <RowDefinition Height="50" /> 
        <RowDefinition Height="50"/> 
       </Grid.RowDefinitions> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition /> 
        <ColumnDefinition /> 
        <ColumnDefinition /> 
        <ColumnDefinition /> 
       </Grid.ColumnDefinitions> 
       <Image x:Name="imageControl" Width="200" Height="200" Source="{Binding DateiSoftwareBitmapSource}" IsTapEnabled="True" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" /> 
       <TextBlock x:Name="txtImageDateDescription" Text="Aufnahmedatum: " Grid.Column="1" Grid.Row="0" /> 
       <TextBlock x:Name="txtImageDescriptionDescription" Text="Beschreibung: " Grid.Column="1" Grid.Row="1" /> 
       <TextBlock x:Name="txtImageDate" Text="{Binding Datum}" Grid.Column="2" Grid.Row="0" /> 
       <TextBox x:Name="txtImageDescription" Text="{Binding Beschreibung}" Grid.Column="2" Grid.Row="1" /> 
       <Button x:Name="btnSpeichern" Content="Speichern" Grid.Column="3" Grid.Row="1" Click="btnSpeichern_Click" /> 
      </Grid> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

をコードでは、私は

lstFotos.ItemsSource = AlleAnzeigeFotos 

AlleAnzeigeFotosを行うbehing(MyClassの)区切りのリストで、MyClassのは、プロパティデータム、Beschreibung、DateiSoftwareBitmapSourceが含まれています

私がしたいのは、ユーザーがテキストフィールドを編集し、ボタンを押してコードを編集できるということです。私はクラスを更新して、さらにいくつかのことをしたいと思います。

ボタンをクリックしたときに、そのクラスの適切なインスタンスを取得するにはどうすればよいですか?

UPDATE: これは、それがどのように見えるかです: enter image description here

"Beschreibung"(英語:説明)(保存)写真を追加した後empyで、編集可能と "Speichern" をクリックして保存しなければなりません。

答えて

3

(sender as Button).DataContextあなたがクリックしたアイテムが表示されます。非常に簡単で、よく説明している、あなたのクラス

更新

Text="{Binding Beschreibung,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 

var userenteredstring=((sender as Button).DataContext as your class).Beschreibung 
+0

の適切な型にキャストします。ありがとうございました! –

+0

しかし、私はTextboxのテキストを取得して、ユーザーが入力したテキストをプロパティ 'Beschreibung'に格納する必要があります。どうすれば入手できますか? –

+0

TwoWayバインドでバインドする必要があります。アップデートは、プロパティチェンジする必要があります。アップデートを確認してください。 – Archana

関連する問題