Question

I might be a bit stupid asking this question. But i have not found anything on the net as of yet with my problem. I have a windows app, a listview displaying Texblocks with names in them and is loaded from a xml file. Here is the xaml code.

<ListView x:Name="listMyLoans" RenderTransformOrigin="0.446,0.54" 
                               Margin="10,150,1052,10" 
                               SelectionChanged="listMyLoans_SelectionChanged_1" 
                               Grid.RowSpan="2">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid Width="300" Height="100" >
                    <TextBlock x:Name="tbTitle" Text="{Binding Title}"></TextBlock >
                    <TextBlock x:Name="tbMediaIndex" Text="{Binding MediaIndex}" 
                                                     Visibility="Collapsed"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

and I need to declare it like to so in code behind. string strMediaIndex = tbMediaIndex.Text;

Something like this but does not work, somehow does not see the TextBlock at all.

Thanks

Était-ce utile?

La solution

You can use Tag property, so you dont have to declare two textbox. Add a new eventhandler to this textbox OnTapped.

And in the Eventhandler you can cast the sender into textBox. When you cast it, you can grab the Tag element and you are ready. Simple and elegant if you are want to use the code-behind.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top