I have a SilverLight project, in the project I have a PDF document.
How to create a reference to the pdf document so it will open with a click on a HyperlinkButton? What should the build action be on the PDF document?
Thanks in advance.
I think, the trick with HyperlinkButton won't work, because you will navigate relate to silverlight project but not associated web project.
You can use file download. I recomend Interlink Upload Download.
Good luck.
You should not include it in the Silverlight project. Instead include it in the associated web project as standard web content. For example if you place it in the web project in a folder called "Documents" then your button will look like:-
<HyperlinkButton Content="LaunchPDF" TargetName="_blank" NavigateUri="/Documents/MyDoc.pdf" />
You can use ICommand:
ViewModel.cs:
private static string _ApplicationUrl;
public static string ApplicationUrl
{
get
{
if (_ApplicationUrl == null)
{
_ApplicationUrl = Application.Current.Host.Source.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped);
//_ApplicationUrl = HtmlPage.Document.DocumentUri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped);
}
return _ApplicationUrl;
}
}
private RelayCommand<string> _WebUriCommand;
public RelayCommand<string> WebUriCommand
{
get
{
if (_WebUriCommand == null)
{
_WebUriCommand = new RelayCommand<string>((p) => { HtmlPage.Window.Navigate(new Uri(ApplicationUrl + p), "_blank"); });
}
return _WebUriCommand;
}
}
View.xaml:
<HyperlinkButton Command="{Binding WebUriCommand}" CommandParameter="/Documents/MyDoc.pdf" Content="Download"/>
Related
trying to setup a multi-tenant site using ABP.io framework 3.1.
I am trying to set the <meta keywords (amongst other tags) in the page html head. I am attempting to get the values from a database field for the current tenant so the meta keywords will be specific for the tenant.
I tried to follow the sample that is available here: https://docs.abp.io/en/abp/latest/UI/AspNetCore/Customization-User-Interface#layout-hooks where they inject a google analytics script code into the head tag.
this is fine, as it is static text, but when i try to load the partial page with a model it throws an error of expecting a different model to that which is passed in.
So far i have the Notification View Componet
Public class MetaKeywordViewComponent : AbpViewComponent
{
public async Task<IViewComponentResult> InvokeAsync() {
return View("/Pages/Shared/Components/Head/MetaKeyword.cshtml"); //, meta);
}
}
and the cshtml page
#using MyCompany.MyProduct.Web.Pages.Shared.Components.Head
#model MetaKeywordModel
#if (Model.SiteData.Keywords.Length > 0)
{
<meta content="#Model.SiteData.Keywords" name="keywords" />
}
and the cshtml.cs file as
public class MetaKeywordModel : MyProductPageModel
{
private readonly ITenantSiteDataAppService _tenantSiteDataAppService;
public TenantSiteDataDto SiteData { get; private set; }
public MetaKeywordModel(ITenantSiteDataAppService tenantSiteDataAppService)
{
_tenantSiteDataAppService = tenantSiteDataAppService;
}
public virtual async Task<ActionResult> OnGetAsync()
{
if (CurrentTenant != null)
{
SiteData = await _tenantSiteDataAppService.GetSiteDataAsync();
}
return Page();
}
}
but when i run the program i get the following error.
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Volo.Abp.AspNetCore.Mvc.UI.Components.LayoutHook.LayoutHookViewModel', but this ViewDataDictionary instance requires a model item of type 'MyCompany.MyProduct.TenantData.Dtos.TenantSiteDataDto'.
How do i pass the data from my database into the page to be rendered if i can't use my model?
Any help tips or tricks would be greatly appreciated.
Regards
Matty
ViewComponent is different from the razor page.
See https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-3.1#view-components
You should inject the service in view component class directly. like:
public class MetaKeywordViewComponent : AbpViewComponent
{
private readonly ITenantSiteDataAppService _tenantSiteDataAppService;
public MetaKeywordViewComponent(ITenantSiteDataAppService tenantSiteDataAppService)
{
_tenantSiteDataAppService = tenantSiteDataAppService;
}
public async Task<IViewComponentResult> InvokeAsync()
{
return View("/Pages/Shared/Components/Head/MetaKeyword.cshtml",
await _tenantSiteDataAppService.GetSiteDataAsync());
}
}
In addition, you can refer https://github.com/abpframework/abp/blob/42f37c5ff01ad853a5425d15539d4222cd0dab69/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/PageAlertsViewComponent.cs
I am using CrossMobile to create an app and I want to use the camera to capture and save photos from my app. I will also need to access the photos taken from the app to show them in a list. How can I present the camera view on a button press?
First of all you might need the CoreImage Plugin, or else some specific permissions will not be available.
Under iOS you also need to add the NSCameraUsageDescription key in the Info.plist by hand, (or else the application will crash due to Apple's limitation).
Let's assume that you have a UIButton with name cameraButton and an UIImageView with name imgV, both initialized in the loadView section of your code.
Then the core would be similar to:
public void loadView() {
// ....
cameraButton.addTarget((sender, event) -> {
if (!UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
new UIAlertView(null, "Unable to access camera", null, "Accept").show();
else {
UIImagePickerController picker = new UIImagePickerController();
picker.setSourceType(UIImagePickerControllerSourceType.Camera);
picker.setDelegate(new UIImagePickerControllerDelegate() {
#Override
public void didFinishPickingMediaWithInfo(UIImagePickerController picker, Map<String, Object> info) {
picker.dismissModalViewControllerAnimated(true);
UIImage img = (UIImage) info.get(UIImagePickerController.OriginalImage);
imgV.setImage(img);
}
#Override
public void didCancel(UIImagePickerController picker) {
picker.dismissModalViewControllerAnimated(true);
}
});
presentModalViewController(picker, true);
}
}, UIControlEvents.TouchUpInside);
// ....
}
Using Geb 0.13.1 here. I'm not trying to integrate it with any kind of testing framework (yet), just trying to get a feel for its DSL. I just want Geb to launch a Firefox browser, point it to Google's homepage and type in 'gmail' in the search address (HTML <input/> with an id of 'q'):
class GoogleHomepage extends Page {
static url = 'http://google.com'
static at = {
title == 'Google'
}
static content = {
search {
$('input#q')
}
}
}
class MyGebDriver {
static void main(String[] args) {
FirefoxDriver firefoxDriver = new FirefoxDriver()
Browser browser = new Browser(driver: firefoxDriver)
Browser.drive(browser) {
to(GoogleHomepage)
search.value('gmail')
quit()
}
}
}
When I run this, Firefox opens up and goes to Google, but seems to choke when finding the search ('q' element) bar to set a value for:
Exception in thread "main" geb.error.RequiredPageContentNotPresent: The required page
content 'sandbox.geb.GoogleHomepage -> search: geb.navigator.EmptyNavigator' is not
present
Any ideas as to what's going on here?
You're getting an EmptyNavigator because you're looking for an input with an id of q $('input#q') try $('input[name=q]') instead.
Your GoogleHomepage looks a bit goofy to me.
What if you made it look more like this which follows the geb dsl better.
class GoogleHomepage extends Page {
url = 'http://google.com'
static at = {
waitFor() {
title == 'Google'
content
}
}
static content = {
search(required: true) { $('input#lst-ib') }
}
}
I'm using CefSharp (47) to render a webpage from a host that I have no control over, and I want to make some additional CSS tweaks to those provided by the host.
Reading up on various topics across GitHub (https://github.com/cefsharp/CefSharp/blob/cefsharp/47/CefSharp.Example/CefSharpSchemeHandlerFactory.cs), and here (CefSharp custom SchemeHandler), I wrote a custom scheme handler accordingly:
public class CustomSchemeHandlerFactory : ISchemeHandlerFactory
{
public const string SchemeName = "custom";
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
{
Console.WriteLine(request.Url);
if (schemeName.ToLower() == SchemeName.ToLower())
{
// Do some stuff
}
return null;
}
}
I attempt to bind it in my application in the following manner:
CefSettings settings = new CefSettings();
settings.CachePath = browserCachePath;
settings.RegisterScheme(new CefCustomScheme()
{
SchemeName = CustomSchemeHandlerFactory.SchemeName,
SchemeHandlerFactory = new CustomSchemeHandlerFactory()
});
Cef.Initialize(settings);
The application then browses to the appropriate website, and uses the 'LoadingStateChanged' event to then fire off some JavaScript to inject the CSS file I want to load:
string linkText = "<link rel=\u0022stylesheet\u0022 type=\u0022text/css\u0022 href=\u0022custom://custom.css\u0022>";
var jsFunctionText = string.Format("(function() {{ $('head').append('{0}'); return true;}}) ();", linkText);
var injectionTask = await _myBrowser.GetMainFrame().EvaluateScriptAsync(jsFunctionText, null);
...which succeeds.
But my custom resource handler 'Create' event is never fired.
I can only presume that the handler isn't being registered properly, so I'd appreciate any advice/help in getting this working properly!
Thanks!
Within the browser I can use this to open a pop-up window:
System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(uri), "_blank");
How do I do this when running outside of the browser?
In an OOB app, you can use the following work around:
Create a derived hyperlink button like this:
public class MyHyperlinkButton : HyperlinkButton
{
public void ClickMe()
{
base.OnClick();
}
}
Use that for navigation:
private void NavigateToUri(Uri url)
{
if (App.Current.IsRunningOutOfBrowser)
{
MyHyperlinkButton button = new MyHyperlinkButton();
button.NavigateUri = url;
button.TargetName = "_blank";
button.ClickMe();
}
else
{
System.Windows.Browser.HtmlPage.Window.Navigate(url, "_blank");
}
}
see forums.silverlight.net
You don't. System.Windows.Browser.HtmlPage is a call to the HtmlPage that is hosting the silverlight application. In out of Browser, you are not hosted by a web page. Trying to do that just hangs the application.
If you have elevated privileges, than you could make an OS call to open a new browser, or I'm sure there are 3rd party controls that act as a hosted browser.
Another way to do this is through ShellExecute:
if (App.Current.IsRunningOutOfBrowser)
{
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
shell.ShellExecute("someURL", "", "", "open", 1);
}
Documentation for ShellExecute is here: http://msdn.microsoft.com/en-us/library/bb774148(VS.85).aspx