I need to be able to load html page with Silverlight module presenting the content based on page was accessed from. For example, if request to open the page come from Page1.html than the content will show Content.1. I tried to work on it but need more information. Any help is highly appreciated:
Here is my code:
HTML: assigned new param:
<param name="inputParams" value="Page1.html" />
It can be a different url string.
Silverlight Code in App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
if (e.InitParams != null)
{
string ValueParam = e.InitParams["value"];
}
}
MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (ValueParam = ?)
{
contentIndex =1;
}
}
The value of the initParams parameter is itself expected to be a series comma separated of name=value pairs.
Your param element should look like this:-
<param name="inputParams" value="value=Page1.html" />
Having said that your specific requirement you can the at the host page's URL via the HtmlPage object.
string path = HtmlPage.Document.DocumentUri.AbsolutePath;
This can save you having to specifically copy the page name into each initParams for each page.
Related
How to go another page in Mysilverlight project. What is the response.redirect in silverlight?
You can use NavigationService.Navigate to load another page:
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
Loaded += Page1_Loaded;
}
private void Page1_Loaded(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("SomeUserControl.xaml", UriKind.Relative));
}
}
Note that the "NavigationService" is a member of the Page class. You can only navigate from within the context of a page or frame -- you can't navigate from within the application itself.
I am trying to update a label control, on a "WPF" page, from my own .cs file but not updating .Please help me.I have a page "Measurements.xaml" ,after page load,in button click create object for my own cs file(sample.cs) and called a method in the cs file.In that method i am trying to update lable control on page (Measurements.xaml),as below
((Measurements)System.Windows.Application.Current.MainWindow).label1.Content = "153";
Measurements.xaml is not a window.
Not sure what you have done or how, but this should work:
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
private void Button1_OnClick(object sender, RoutedEventArgs e)
{
var sample = new Sample();
sample.UpdateLabel();
}
}
class Sample
{
public void UpdateLabel()
{
var main = (MainWindow) Application.Current.MainWindow;
main.Label1.Content = "153";
}
}
I have problem with awesomium web control 1.7.4 in WPF , when the user click links in page , awesomium navigate to targetURL , but i want to open that links in system default browser.
also I want to determine mailto:jondue#example.com to open this links in default Email client.
Please help me.
Thanks
Update :
I've been doing some more searching to solve my problem, after few days I founded that when the link has a target=_blank the event ShowCreatedWebView is fired. The main problem was about links without target=_blank. After that I'm able to find links without that cause firing event RequestBringIntoView.
private void Browser_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
}
and
private void Browser_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
if (Browser.TargetURL != new Uri("about:blank"))
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
e.Handled = true;
}
}
I've been doing some more searching to solve my problem, after few days I founded that when the link has a target=_blank the event ShowCreatedWebView is fired. The main problem was about links without target=_blank. After that I'm able to find links without that cause firing event RequestBringIntoView.
private void Browser_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
}
and
private void Browser_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
if (Browser.TargetURL != new Uri("about:blank"))
{
System.Diagnostics.Process.Start(Browser.TargetURL.AbsoluteUri);
e.Handled = true;
}
}
You could try using IResourceInterceptor to decide what you want to do when Awesomium loads a page.
public partial class MainWindow : Window
{
public MainWindow()
{
WebCore.Initialize(new WebConfig());
WebCore.Initialized += ((object sender, CoreStartEventArgs e) =>
{
WebCore.ResourceInterceptor = new ResourceInterceptor("http://google.com/");
});
InitializeComponent();
}
}
public class ResourceInterceptor : IResourceInterceptor
{
//Url of the first page to be loaded inside webcontrol without redirection.
protected string m_startupURL;
public ResourceInterceptor(string startupURL)
{
m_startupURL = startupURL;
}
public virtual bool OnFilterNavigation(NavigationRequest request)
{
if (request.Url.ToString() != m_startupURL)
{
System.Diagnostics.Process.Start(request.Url.ToString());
return true;
}
return false;
}
public ResourceResponse OnRequest(ResourceRequest request)
{
return ResourceResponse.Create(request.Url.OriginalString);
}
}
This is a very basic implementation. You should add some additional tests on the Url. Actually Process.Start(request.Url.ToString()) can do anything (launching an application or formatting your disk). So don't forget to test whether it is a valid Url or a mailto: link.
I'm new at Silverlight.
I've created a sort of master page using a Page with a frame where the content is loaded. As I handle multiple UserControls at the time (only one is shown, but I want to keep the state of the opened before) I'm setting Content property instead of Navigate method. That way I can assign a UserControl (already created, not a new one as it would be using Navigate with the Uri to the UserControl).
Now I want to take a picture as shown here from the frame when its content changes. If I do it immediately when the content set, the UserControl won't be shown in the picture because it takes a few secs. Frames have the event Navigated, but it doesn't fire with property Content (it just fires when the method Navigate is used, as it name says).
How can I know when new Content is loaded?
If it helps I'm using Silverligh 5.
I've a solution but I don't really like it, so I'm still looking for other ways.
public class CustomFrame : Frame
{
private readonly RoutedEventHandler loadedDelegate;
public static readonly DependencyProperty UseContentInsteadNavigationProperty =
DependencyProperty.Register("UseContentInsteadNavigation", typeof (bool), typeof (CustomFrame), new PropertyMetadata(true));
public bool UseContentInsteadNavigation
{
get { return (bool)GetValue(UseContentInsteadNavigationProperty); }
set { SetValue(UseContentInsteadNavigationProperty, value); }
}
public CustomFrame()
{
this.loadedDelegate = this.uc_Loaded;
}
public new object Content
{
get { return base.Content; }
set
{
if (UseContentInsteadNavigation)
{
FrameworkElement fe = (FrameworkElement)value;
fe.Loaded += loadedDelegate;
base.Content = fe;
}
else
{
base.Content = value;
}
}
}
void uc_Loaded(object sender, RoutedEventArgs e)
{
((UserControl)sender).Loaded -= loadedDelegate;
OnContentLoaded();
}
public delegate void ContentLoadedDelegate(Frame sender, EventArgs e);
public event ContentLoadedDelegate ContentLoaded;
private void OnContentLoaded()
{
if (ContentLoaded != null)
ContentLoaded(this, new EventArgs());
}
}
I have some problem with my code. I have silverlight button after I press button I want to load document library and get information about how many items are in this library co my code is:
var web = context.Web;
List sharedDocumentsList = context.Web.Lists.GetByTitle("dokumenty");
int i = sharedDocumentsList.ItemCount;
context.Load(sharedDocumentsList);
context.ExecuteQueryAsync(OnFileWriteSucceeded, OnFileWriteFailed);
But I got still same problem.
The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explixitly requested
How Can I get ItemCount. This is only a simple example I need to work with this list in cycle and so on. But I need to solve this main problem. How to work with this documentlist directly in button click method.
Thank You.
This works for me:
private List docList;
private void GetList()
{
var context = new ClientContext(ApplicationContext.Current.Url);
context.Load(context.Web);
docList = context.Web.Lists.GetByTitle("dokumenty");
context.Load(docList);
context.ExecuteQueryAsync(GetListSucceded, GetListFailed);
}
private void GetListFailed(object sender, ClientRequestFailedEventArgs e)
{
Dispatcher.BeginInvoke(() => MyErrorFunction();
}
private void GetListSucceded(object sender, ClientRequestSucceededEventArgs e)
{
Dispatcher.BeginInvoke(() => GetItemsCount());
}
private void GetItemsCount()
{
MessageBox.Show(docList.ItemCount.ToString());
}