I have a flipview which is populated by some code (I don't understand how modifying an app).
<FlipView x:Name="ArticleDetail" Grid.Row="1" AutomationProperties.AutomationId="ItemsFlipView" AutomationProperties.Name="Item Details" TabIndex="1"
DataContext="{Binding LatestArticlesModel}"
ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource LatestArticles1DetailDetail}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
ItemContainerStyle="{StaticResource FlipItemStyle}">
</FlipView>
<!--Data template for flipview-->
<DataTemplate x:Key="LatestArticles1DetailDetail">
<ScrollViewer>
<StackPanel>
<TextBlock Margin="0,16"
Text="{Binding Title, Converter={StaticResource TextPlainConverter}, ConverterParameter = 140}"
Style="{StaticResource SubHeaderText}" />
<Image Source="{Binding ImageUrl, Converter={StaticResource ThumbnailConverter}, ConverterParameter=300}" Stretch="UniformToFill" />
<TextBlock
x:Name="FeedUrl"
Margin="0,12" Style="{StaticResource Html2XamlStyleText}"
Text="{Binding FeedUrl}"
Visibility="Collapsed"/>
<RichTextBlock
x:Name="Content"
Margin="0,12"
Style="{StaticResource Html2XamlStyle}"/>
</StackPanel>
</ScrollViewer>
</DataTemplate>
From the textblock named "FeedUrl" I want to extract the url which is stored in it.
Use the url to parse the html page pointed to by that url
After processing display some content in the richtextblock named "content".
The only problem I am facing in it is how to get reference to the textblock and richtextblock inside each item of the flipview.
For getting reference to items I have tried two solutions:
- I've tried this code but the line
var myTextBlock= _Children.OfType<TextBlock>().FirstOrDefault(c => c.Name.Equals("test"));
specifically
.OfType<TextBlock>()
gives an error
'System.Collections.Generic.List<Windows.UI.Xaml.Controls.TextBlock>' does not contain a definition for 'OfType' and no extension method 'OfType' accepting a first argument of type 'System.Collections.Generic.List<Windows.UI.Xaml.Controls.TextBlock>' could be found (are you missing a using directive or an assembly reference?)
- I also tried another solution given here, but I always get a null reference.
I also get a warning for the line
var item = itemsControl.ItemContainerGenerator.ContainerFromItem(o);
Windows.UI.Xaml.Controls.ItemContainerGenerator.ContainerFromItem(o); is obsolote.'ContainerForm' may be unavailable for releases after Windows Phone 8.1. Use itemsControl.ContainerFromItem instead.
Even if I use itemsControl.ContainerFromItem
it always returns a null reference.
Please Help
UPDATE:
I'm using the following
if(!statusiop.statusup){
this.UpdateLayout();
for (int i = 0; i < ArticleDetail.Items.Count; i++)
{
var fvItem = this.ArticleDetail.Items[i];
var container = this.ArticleDetail.ContainerFromItem(fvItem);
if (container == null)
{
Text = "null container";
}
else
{
var tbFeedURL = FindElementByName<TextBlock>(container, "FeedUrl");
if (tbFeedURL == null)
{
test.Text = "null text";
}
else
{
tbFeedURL.Text = tbFeedURL.Text + "Test";
}
}
}
I iterate through all the items in the flipview, and modify the data as needed. I am also using a public static class
public static class statusiop
{
public static Boolean statusup= false;
}
which contains a member statusup. statusup serves as a flag which when true indicates that the flipview data has been updated once and need not be updated again.
See Question&Answers more detail:
os