how to get current textpointer/offset of RichTextBlock in a scrollviewer - windows-runtime

I have a richtextblock in a scrollviewer, the content of the richtextblock is very long. When I scroll the content, how can I get the first word/textpointer/offset
I've tried to calculate the current offset by
private void _scrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
CurrentOffset = (int)((_scrollViewer.VerticalOffset / _scrollViewer.ScrollableHeight) * _richTextBlock.ContentEnd.Offset);
}
But it's not accurate.

Related

How to scroll sidebar google maps in order to fetch all results on Selenium Java?

I have a google map search that I would like to extract with Selenium Java. The code above only gets 7 or 8 results.
public class A {
public static void main(String[] args) throws IOException, InterruptedException {
...
String urlGmaps = "https://www.google.com/maps/search/Air+Conditioning+Contractor+Air+Conditioning+Repair+Service+Contractor+OR+OR+OR+Repair+OR+Service+%22SAN+DIEGO%22/#32.7916817,-117.9672179,8z/data=!3m1!4b1";
driver.get(urlGmaps);
driver.manage().window().maximize();
Thread.sleep(8000);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[3]/div[9]/div[9]/div/div/div[1]/div[2]/div/div[1]/div/div/div[2]/div[1]")));
String scrolling_element_xpath="/html/body/div[3]/div[9]/div[9]/div/div/div[1]/div[2]/div/div[1]/div/div/div[2]/div[1]";
//identify elemet which will appear after scrolling
// identify scrolling element first i.e. the sidebar
WebElement scrolling_element = driver.findElement(By.xpath(scrolling_element_xpath));
// use height of element to determine if need to scroll
long last_height = (long) ((JavascriptExecutor) driver).executeScript("return arguments[0].scrollHeight", scrolling_element);
System.out.println(last_height);
// pause before next scroll, to let page load
int SCROLL_PAUSE_TIME = 2;
int t = 0; // number of times we have scrolled
// Loop the scrolling until cannot scroll anymore
while (true) {
System.out.println(t);
// Scroll down to bottom of whatever is currently loaded
((JavascriptExecutor) driver).executeScript("return arguments[0].scrollHeight", scrolling_element);
t = t+1;
// Wait to load page
try {
Thread.sleep((long) (SCROLL_PAUSE_TIME*1000));
} catch (InterruptedException e) {
e.printStackTrace();
}
// Check if more scrolling required
long new_height = (long) ((JavascriptExecutor) driver).executeScript("return arguments[0].scrollHeight", scrolling_element);
System.out.println(new_height);
if (new_height == last_height) {
break;
}
last_height = new_height;
}
Document doc = Jsoup.parse(driver.getPageSource());
Elements elements = doc.getAllElements();
for(Element e: elements) {System.out.println(e.text());}
}
}
I've increased the amount of time int SCROLL_PAUSE_TIME = 2; and didn't work. I'd like to fetch all results in the sidebar

Display images in observable collection one after the other as user scrolls in windows phone 8

I have a json array of image URLs added into an observable collection and I want to display the first image on the page such that when a user scrolls horizontally, next or previous images in the array shall display on the screen. Help me achieve this.
Here's how I download the image URLs via json and add them to the observable collection
public event PropertyChangedEventHandler PropertyChanged;
private ObservableCollection<readPageModel> readPages = new ObservableCollection<readPageModel>();
public ObservableCollection<readPageModel> Read_Pages
{
get
{
return readPages;
}
set
{
readPages = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Read_Pages"));
}
}
}
public void DownloadData()
{
WebClient client = new WebClient();
client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://########/mob/ranges/id/3/limit/10/offset/0/r_id/6", UriKind.Absolute));
}
private void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(e.Result))
{
string data = e.Result;
var items = JsonConvert.DeserializeObject<readModel[]>(data);
foreach (var x in items)
{
Read_Pages.Add(x);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
You can take scrollviwer in the xaml after this within this scrollviewer take stack panel with horizontal orientation. and then from c# code add image control to this stack panel.
You can have one image control in content panel and implement below code :
public Page()
{
InitializeComponent();
GestureListener gestureListener = GestureService.GetGestureListener(ContentPanel);
gestureListener.DragCompleted += gestureListener_DragCompleted;
//set the initial image to Image control
}
void gestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
{
// User flicked towards left
if (e.HorizontalVelocity < 0)
{
// Load the next image if Downloaded
}
// User flicked towards right
if (e.HorizontalVelocity > 0)
{
// Load the previous image
}
}
you would also needed to have one variable for tracking the index of image to be loaded

Navigate to the same View. Why Loaded and OnNavigatedTo events aren't called?

Im doing a cloud App(like Skydrive) in Windows Phone 8 , each time I navigate to a different folder I need to reload the FolderView.xaml page to display the content of this folder and I need to add the view to the back stack then I will be able to back to the previous path...
From now when I try to reload the FolderView from the FolderView.xaml.cs page, none event is called...
I don't understand why ? And if you have a solution you are welcome ...
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (App.ElementSelected != null)
{
BdeskElement FolderChoosen = new BdeskElement();
FolderChoosen = App.ElementSelected;
Gridentete.DataContext = FolderChoosen;
GetFiles(FolderChoosen);
}
}
private async void llsElements_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
LongListSelector llselement = null;
listElementCollection.Clear();
if (sender != null)
llselement =(LongListSelector)sender;
if(llselement.SelectedItem!=null)
{
BdeskElement bdelement=(BdeskElement)llselement.SelectedItem;
if (bdelement.TypeElement==BdeskElement.BdeskTypeElement.Folder)
{
App.DocLibSelected = null;
App.ElementSelected = bdelement;
// I navigate to the same view here but nothing happens
NavigationService.Navigate(new Uri("/Views/BDocs/FolderView.xaml", UriKind.RelativeOrAbsolute));
}
}
}
To navigate to the same page with a new instance, you must change the Uri. For example:
NavigationService.Navigate(new Uri(String.Format("/Views/BDocs/FolderView.xaml?id={0}", Guid.NewGuid().ToString()), UriKind.Relative));
You can discard that parameter if you don't want/use it.

Get the delta value from PointeWheelChanged event for WinRT

Is there any way to get the delta value from PointeWheelChanged event in WinRT?
The following works in the RTM of Windows Runtime, it will log the result to the Debug window. Positive values are up (away from you), negative values are scrolling down (towards you). Important is to set handled to true so that this event doesn't bubble further up the UI elements.
private void ZoomPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.GetCurrentPoint(this).Properties.MouseWheelDelta);
e.Handled = true;
}
Following code works well,
private void PointerWheelChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
{
var wheelDelta = args.CurrentPoint.Properties.MouseWheelDelta;
// do something with the delta
}

how to extract html code for website using iframe and silverlight

I need to load a specific webpage from a site that has multiple images on the site. I need to extract these images but I can't do this manually because the names of each image have no pattern and there will be hundreds of sites. I have a silverlight application to load the webpage in an iframe and I intended on extracting the html for this webpage and then retrieving the image source for each image from the extracted code and then populating a listbox.
I can load the web page in iframe with no problem, but I don't know how to retrieve the html code for the webpage.
public Page()
{
InitializeComponent();
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null)
{
myFrame.SetStyleAttribute("width", "1024");
myFrame.SetStyleAttribute("height", "768");
myFrame.SetAttribute("src", txtURI.Text);
myFrame.SetStyleAttribute("left", "0");
myFrame.SetStyleAttribute("top", "50");
myFrame.SetStyleAttribute("visibility", "visible");
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Button_Click(sender, e);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
System.Windows.Browser.HtmlElement myFrame = System.Windows.Browser.HtmlPage.Document.GetElementById("ifHtmlContent");
if (myFrame != null) myFrame.SetAttribute("src", txtURI.Text);
}
private void txtURI_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
this.Button_Click(sender, e);
}
The following article may offer some help:
http://jesseliberty.com/2010/05/03/screen-scraping-when-all-you-have-is-a-hammer/