I have been using SaveToString() method to get the source code of the page in WebBrowser Control. But since its been deprecated in Windows 10, Whats the equivalent for SaveToString() in WebView Control of Windows 10.
WebView allows us to invoke script, and we can dump the document.documentElement.outerHTML to do the same thing as SaveToString().
The following shows a very simple sample for your test. Note that I didn't try to make a cool UI design and make all things formatted, but only try to show you the idea.
In xaml:
<StackPanel>
<WebView x:Name="MyWebView" Source="http://www.bing.com" Height="200"
DOMContentLoaded="MyWebView_DOMContentLoaded"/>
<Button x:Name="ViewSourceBtn" Content="View Source" Click="ViewSourceBtn_Click"/>
<RichTextBlock x:Name="SourceBlock" Height="300" >
</RichTextBlock>
</StackPanel>
Code behind:
bool contentloaded = false;
private async void ViewSourceBtn_Click(object sender, RoutedEventArgs e)
{
if (contentloaded)
{
string html = await MyWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
var paragraph = new Paragraph();
paragraph.Inlines.Add(new Run { Text = html });
SourceBlock.Blocks.Clear();
SourceBlock.Blocks.Add(paragraph);
}
else
{
string err = "Waiting for HTML content to load!";
var paragraph = new Paragraph();
paragraph.Inlines.Add(new Run { Text = err });
SourceBlock.Blocks.Clear();
SourceBlock.Blocks.Add(paragraph);
}
}
private void MyWebView_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
{
contentloaded = true;
}
Here is the result by clicking view source button:
Related
Xamarin iOS is testing me lately. I have a form which has as Entry value for searching. This entry control has a text changed event. All works great , event executes and values passed as expected however the results dont appear on screen.
If i rotate the device, in this case and ipad, the results show. Everything in Android works as expected. Frustrating
CancellationTokenSource _cts;
private void Search_TextChanged(object sender, TextChangedEventArgs e)
{
try
{
_cts?.Cancel(); // cancel previous search
}
catch { } // in case previous search completed
ShowResults((Entry)sender);
}
private async void ShowResults(Entry entry)
{
using (_cts = new CancellationTokenSource())
{
try
{
await Task.Delay(TimeSpan.FromSeconds(1), _cts.Token); // buffer
using (UserDialogs.Instance.Loading("Loading. . ."))
{
ObservableCollection<TMDB_Movie> itemSourceCollection = new ObservableCollection<TMDB_Movie>();
MovieSearchVM context = (MovieSearchVM)BindingContext;
try
{
if (!IsPublicCollection)
{
var results = PrivateCollection.Where(x => x.Title.Contains(entry.Text));
foreach (TMDB_Movie movie in results)
{
movie.PublicCollection = true;
movie.Type = "Digital";
itemSourceCollection.Add(movie);
}
}
else
{
if (PhysicalDevice.HasInternetConnection())
{
TMDB_Request request = new TMDB_Request();
TMDB_Movies movies = await request.ByMovieName(entry.Text, CustomSettings.GetSettings().Language);
int i = 0;
foreach (var movie in movies.Results)
{
if (i < 10)
{
FanartTv tv = new FanartTv();
movie.Movieposter = await tv.GetSingleMoviePoster(movie.Id);
if (movie.Release_date != null)
{
char[] Separator = new char[] { '-' };
string[] year = movie.Release_date.Split(Separator, StringSplitOptions.None);
movie.Release_year = year[0];
}
movie.PublicCollection = true;
itemSourceCollection.Add(movie);
i++;
}
else
{
break;
}
}
}
}
context.MovieCollection = itemSourceCollection;
}
catch { }
}
}
catch { }
}
}
View Model
private ObservableCollection<TMDB_Movie> _MovieCollection = new ObservableCollection<TMDB_Movie>();
public ObservableCollection<TMDB_Movie> MovieCollection
{
get { return _MovieCollection; }
set
{
_MovieCollection = value;
RaisePropertyChanged("MovieCollection");
}
}
XAML
<Grid Style="{StaticResource StyleBaseGrid}" Grid.Row="2" HorizontalOptions="FillAndExpand" >
<SfListView:SfListView x:Name="GridMovieCollection"
ItemsSource="{Binding MovieCollection}"
ItemTemplate="{StaticResource StandardPosterTemplate}"
Margin="-5,0,0,0"
ItemSize="125"
ItemSpacing="0,0,0,0"
AutoFitMode="None"
SelectionBackgroundColor="Transparent"
ItemHolding="GridMovieCollection_ItemHolding"
ItemTapped="GridMovieCollection_ItemTapped" >
</SfListView:SfListView>
</Grid>
I have no clue why rotation solves this but i guess it updates the controls width and height properties and refreshes the screen.
Any ideas how i can force refresh the screen or if there is anything wrong with my code?
Android look
I found below code and trying to modify it to print an specific div element. Below code opens print dialog but shows empty screen. I dont know where to put my id of div element in the code.
print(){
var doc = new jsPDF("portrait", "mm", "a4");
doc.autoPrint();
const hiddFrame = document.createElement('iframe');
hiddFrame.style.position = 'fixed';
// "visibility: hidden" would trigger safety rules in some browsers like safariļ¼
// in which the iframe display in a pretty small size instead of hidden.
// here is some little hack ~
hiddFrame.style.width = '1px';
hiddFrame.style.height = '1px';
hiddFrame.style.opacity = '0.01';
const isSafari = /^((?!chrome|android).)*safari/i.test(window.navigator.userAgent);
if (isSafari) {
// fallback in safari
hiddFrame.onload = () => {
try {
hiddFrame.contentWindow.document.execCommand('print', false, null);
} catch (e) {
hiddFrame.contentWindow.print();
}
};
}
var blob = doc.output("blob");
window.open(URL.createObjectURL(blob), '_blank');
}
I want to open a new window, configured with height and width, all while using < h:commandLink >
<h:commandLink id="zyzid" value="click me" action="#{test.testDo}" target="_blank" />
this renders into:
<a onclick="mojarra.jsfcljs(document.getElementById('myForm'),{'myForm:xyzid':'myForm:xyzid'},'_blank');return false" href="#" id="myForm:xyzid">click me</a>
I looked at jsfcljs() function. It submits the form with target="_blank", but i don't see window.open() anywhere. So, how would I be able to alter this code to change new window's height and width?
for reference:
mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
mojarra.apf(f, pvp);
var ft = f.target;
if (t) {
f.target = t;
}
f.submit();
f.target = ft;
mojarra.dpf(f);
};
I found a few relevant links, and this and I arrived at this solution, which seems to work for me. h:commandLink opens a new page, and I get to manipulate it's width and height. This involves slightly modifying/overwriting the mojarra.jsfcljs function. It opens a window with standard window.open() (triggered by onclick) and associates the form it is submitting with that window.
$(window).load(function(){
mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
mojarra.apf(f, pvp);
var ft = f.target;
if (t) {
if (t.indexOf('options') != -1){
f.target = '_blank' + new Date().getTime();
var options = t.substring(t.indexOf('optionts') + 9);
window.open('', f.target, options);
}
else{
f.target = t;
}
}
f.submit();
f.target = ft;
mojarra.dpf(f);
};
});
markup:
< h:commandLink id="viewLink" action="#{testBean.doTest}" value="h:commandLink" target="options:height=200, width=300" />
Do we have any option to disable the save and publish button available in umrbaco programmatically.?
If you don't want to modify the source, here's a down & dirty way to disable it using ApplicationBase to inject some jQuery:
public class RemoveToolbarButtons : ApplicationBase
{
public RemoveToolbarButtons()
{
umbracoPage.Load += new umbraco.presentation.masterpages.MasterPageLoadHandler(umbracoPage_Load);
}
void umbracoPage_Load(object sender, EventArgs e)
{
var page = (umbracoPage)sender;
if (page.Page.Request.Path.ToLower().Replace((GlobalSettings.Path + "/").ToLower(), "").Contains("editcontent.aspx"))
{
var currentDocId = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
Document d = new Document(currentDocId);
if (d.ContentType.Alias == "YourDocTypeAlias")
{
string s = #"<script type='text/javascript'>
$(document).ready(function() {
$('.editorIcon').each(function() { if(String($(this).attr('alt')) == 'Save and publish') {$(this).hide(); return false;} });
});
</script>";
page.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jshidetoolbar", s);
}
}
}
}
Change YourDocTypeAlias to the doctypealias where you want to disable it. Note this only hides the button using jQuery, the user may still have access to Publish via the context menu or other methods.
Minor tweak to Tom's approach - adjust the jQuery to not return false (otherwise it only hides the first 'Save and publish' button when you have multiple tabs)
string s = #"<script type='text/javascript'>
$(document).ready(function() {
$('.editorIcon').each(function() { if(String($(this).attr('alt')) == 'Save and publish') {$(this).hide(); } });
});
</script>";
The full-source code for Umbraco is available as an open source project, so yes, you can disable the save and publish (and do anything else you want).
Link
I am writing a simple "Book" create page in ASP.NET MVC. User can create book by filling title,year etc.. and selecting a cover image. When user press "Create" button Form sends image and data to Controller action called "Create" then I save image to disk and data to database.
But I want to display image when user select image by file dialog.To do this As far as I know I must upload image to server then display in client browser.But if a user cancels the "Create" operation after uploading image, the image will remain in the server's disk.So How can I deal with these temp images or Is there any way to display image in client browser without upload to server?
Due to security reasons, you will not be able to display the images to the users without uploading them to the server. Displaying images from file system is considered a security risk.
EDIT: To remove the unused images, you can create a thread to run a cleanup routine to which will delete them from the upload directory regularly.
Yes, using Silverlight, for example:
In Page.xaml:
<StackPanel x:Name="LayoutRoot" Background="White">
<Button x:Name="btn1" Content="Select image file">
<Image x:Name="img1">
</StackPanel>
and in Page.xaml.cs:
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
btn1.Click += new RoutedEventHandler(btn1_Click);
}
void btn1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == true)
{
Stream s = ofd.File.OpenRead();
BitmapImage bi = new BitmapImage();
bi.SetSource(s);
img1.Source = bi;
s.Close();
}
}
}
Read more here.
Yes, you can using javascript
Javascript:
function showThumbnail(files){
for(var i=0;i<files.length;i++){
var file = files[i]
var imageType = /image.*/
if(!file.type.match(imageType)){
console.log("Not an Image");
continue;
}
var image = document.createElement("img");
var thumbnail = document.getElementById("thumbnail");
image.file = file;
thumbnail.appendChild(image)
var reader = new FileReader()
reader.onload = (function(aImg){
return function(e){
aImg.src = e.target.result;
};
}(image))
var ret = reader.readAsDataURL(file);
var canvas = document.createElement("canvas");
ctx = canvas.getContext("2d");
image.onload= function(){
ctx.drawImage(image,100,100)
}
}
}
var fileInput = document.getElementById("upload-image");
fileInput.addEventListener("change",function(e){
var files = this.files
showThumbnail(files)
},false)
HTML:
<input type="file" id="upload-image" multiple="multiple"></input>
<div id="thumbnail"></div>
You just need the input field and The div to display the thumbnail image, and on change for the input field will call showThumbnail function which will append img inside the "thumbnail" div.
You can do it with Simple javascript...
assign the selected image path.. to image tag prefixing the file://, n it works the way you want it to be