I have a Silverlight application in which I display some phone numbers. I want that numbers to be displayed as links and when the user clicks on the links to be redirected to skype. (The same as on html).
This is the equivalent in html (just to understand what i need):
+11 11 111 11 11
In silverlight I tried with:
<HyperlinkButton Content="{Binding}" NavigateUri="{Binding StringFormat=callto:\{0\}}" />
but I get System.InvalidOperationException: Failed to navigate to callto:+11 11 111 11 11.
Does somebody knows a solution for this?
Can you try using Javascript to invoke that sort of anchor? If you're able to do this via Javascript, try using the Eval function to invoke the Javascript from Silverlight:
HtmlPage.Window.Eval();
This may be a little late, but if you still want to keep it in Silverlight code, then this will work:
Public Class MyHyperLink : Inherits HyperlinkButton
Sub New(ByVal uri As String)
MyBase.NavigateUri = New Uri(uri)
End Sub
Public Sub Execute()
Application.Current.Host.Content.IsFullScreen = False
MyBase.TargetName = "_blank"
MyBase.OnClick()
End Sub
End Class
And to call, add the following code::
Dim nav As New MyHyperLink(URL)
nav.Execute()
Related
Im using WPF and VB.net and in order to use a picture (source) for an image you need the file to be in the folder of the application, so the source of stack.png would be stack.png.
But I want to use C:/APictureLocation/stack.png. I think Releative file name maybe? I honestly do not know how to ask a question without explaining. Sorry.
So I can do:
image.source = "C:\APictureLocation\stack.png"
instead of
image.source = "stack.png"
Thanks for you help!
Do not vote down without giving me pointers. Doesn't help the community.
My answer!
Private Sub BrowseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
Dim dialog As New OpenFileDialog()
dialog.InitialDirectory = "C:\"
dialog.ShowDialog()
picbox.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri(dialog.FileName, UriKind.Absolute))
End Sub
I believe I have the solution to your problem (or what I think your asking)...
Let's say your image source folder is 'C:\Images\ProgramImages'
(notice how I have used a '\' not a '/' in my path...)
Firstly, create a new form called 'ImageBrowser'. Then, add a ListBox control and name it 'ImageBrowserLB'. After this, double click on the ImageBrowser form so it takes you to the code editor. In the auto-generated sub, type the following:
For Each F As File In System.IO.Directory.GetFiles("C:\Images\ProgramImages\")
If Path.Extension(F) = ".png" Then
ImageBrowserLB.Items.Add(Path.GetFileName(F))
End If
Next
When that form loads, it will add all the files with a PNG extension in the directory I specified. I'm sure you can take this code and manipulate it to do what you would like (which isn't very clear in your question!).
Hope this helped,
Rodit
I'm using a version of the common RelayCommand class and trying to pass a command parameter but not having success. I get the following error:
Error 29 Method 'Private Sub KeyPadPressExecute(param As Object)' does not have a signature compatible with delegate 'Delegate Sub Action()'.
I've looked at the many examples of using parameters with commands, but I can't make sense out of them. I don't understand where I'm supposed to get the parameter from that will be passed on to KeyPadPressExecute().
Here's the relevant code:
Private Sub KeyPadPressExecute(param As Object)
Debug.Print(param.ToString)
End Sub
Private Function CanKeyPadPressExecute() As Boolean
Return True
End Function
Public ReadOnly Property KeyPadPress() As ICommand
Get 'Error occurs on next line
Return New RelayCommand(AddressOf KeyPadPressExecute, AddressOf CanKeyPadPressExecute)
End Get
End Property
What my XAML looks like:
<Button Command="{Binding KeyPadPress}" CommandParameter="1" Width="84"></Button>
I'm using VS 2012 and targeting .NET 4.5.
Note: My original post said I was using MicroMVVM. Closer inspect of the project indicates that the assembly named MicroMVVM is not related to the MicroMVVM framework hosted at codeplex. This project was started by someone else, thus the confusion.
From a RelayCommand implementation seen at GitHub, one can tell that the class effectively hides and swallows the command parameter. Perhaps you should try to use the generic version of the class instead: RelayCommand(Of T). The run-time exception is pretty clear: there's a mismatch between the MicroMVVM class's constructor, taking only a blunt Sub Action() delegate; and your command's execute handler, taking an object argument.
NB: Please forgive my bad VB, it's not my mother tongue.
Update: I see that MicroMVVM is hosted at CodePlex, but there's no RelayCommand class in there (apparently replaced by the smarter DelegateCommand class). The link to the probably unrelated project at GitHub still serves its purpose as an example and source of information. Comments are welcome.
I have some code that works in winforms, but not in WPF apparently, the code is as follows:
This is set globally:
Private Property avar As Object
Public main As MainWindow
Public charchoice As Char
And then in the Window Loaded sub, this is placed:
charchoice = main.charchoice
Thing is, the next window doesn't pick up this variable, so how can I make it recognise and use it? Thanks Guys
Nick
I had a similar problem and discovered that you must create a public property in the MainWindow and pass a value to the property.
Please see this example from a similar question I posted.
Hey i got same problem when i am going to pass values between two forms.
I find its solution using a simple class and Shared property.
First I create a class named with cls_pass_val which is as under:-
Public Class cls_pass_val
Private Shared var_pass_val As String = ""
Public Shared Property Pass_val() As Char
Get
Return var_pass_val
End Get
Set(ByVal value As String)
var_pass_val = value
End Set
End Property
End Class
Now at the time of assigning a value:
cls_pass_val.Pass_val='A'
and at the time of retrieving the value:
Dim var_c as Char
var_c=cls_pass_val.Pass_val
Has anyone using VB.NET 2010 been able to create a single instance application?
I've followed the MSDN sample but it does not have an Application.xaml file.
Converting any C# samples to VB doesn't work as I cannot override the Main sub in Application.xaml (C# calls it App.xaml).
You can try using a Mutex. In the projects properties, disable the application framework and set Sub Main as the startup object. Then add a Module to your project:
Imports System.Threading
Module EntryPoint
Sub Main()
Dim noPreviousInstance As Boolean
Using m As New Mutex(True, "Some Unique Identifier String", noPreviousInstance)
If Not noPreviousInstance Then
MessageBox.Show("Application is already started!")
Else
Dim mainWindow As New MainWindow()
Dim app As New Application()
app.Run(mainWindow)
End If
End Using
End Sub
End Module
With this method, you will have to take care of your app's shutdown by calling the Shutdown method of the application.
Here's a few possible solutions. I'd look through the whole thread here before deciding on one. Make sure you backup your code before trying any of these, so if one doesn't work, you can try another.
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/6c15b837-9149-4b07-8a25-3266949621a7/
update 5: brians solution worked:
namespace Module1
type Page1() as this =
inherit UserControl()
let uriStr = "/FSSilverlightApp;component/Page1.xaml"
let uri = new System.Uri(uriStr, System.UriKind.Relative)
do
Application.LoadComponent(this, uri)
member public this.Uri with get () = uri
type MyApp() as this =
inherit Application()
do Application.LoadComponent(this, new System.Uri("/FSSilverlightApp;component/App.xaml", System.UriKind.Relative))
let nav : Frame = siteTemplate ? contentFrame
let p1 = new Module1.Page1() ;
member this.navigate ea =
nav.Navigate(p1.Uri)
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Module1.MyApp">
<Application.Resources>
</Application.Resources>
</Application>
<UserControl x:Class="Module1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<TextBlock Text="This is page 1 Lets see if we can ever get here!!!" FontSize="24" />
</Grid>
</UserControl>
update 4:
the template Brian has mentioned is mostly doing the trick. I still have a more complex page that is giving me troubles - yet it is most likely my code. Once my code is complete I will post what I can diagnose but the parts include:
Setting App.XAML correctly (referencing your application object correctly)
in post construction of your application object use Application.Load to load the App.xaml
In your application object create instances of your page xaml
in post construction of your page objects use Application.Load to load the individual page.xaml
each of your page objects should extend UserControl; I suspect this is not truly the case - once I get more more complex page running I will see if removing this restriction will have an effect.
update 3:
I implemented my own controller logic in the Application object, which seems to do part of the trick (and solve my needs for a prototype anyhow).
type Page1() as this =
inherit Page()
do
this.Content <- loadXaml("Page1.xaml")
type MyApp() as this =
inherit Application()
let cc = new ContentControl()
let mainGrid : Grid = loadXaml("MainWindow.xaml")
let siteTemplate : Grid = if mainGrid.Name = "siteTemplate" then mainGrid else mainGrid ? siteTemplate
let nav : Frame = siteTemplate ? contentFrame
let page1 = new Module1.Page1() :> Page ;
let page2 = new Module1.Page2() :> Page ;
let page3 = new Module1.Page3() :> Page ;
do
this.Startup.Add(this.startup)
// to be able to get focus
cc.IsTabStop <- true
cc.IsEnabled <- true
System.Windows.Browser.HtmlPage.Plugin.Focus()
cc.Content <- mainGrid
this.RootVisual <- cc
member this.startup ea =
menu.MenuItemClicked.Add(this.navigate)
resolutionSlider.SizeChanged.Add(this.resizeTemplate)
member this.navigate ea =
if ea.Index = 1 then nav.Content <- page1
elif ea.Index = 2 then nav.Content <- page2
elif ea.Index = 3 then nav.Content <- page3
It works... I don't know the implication on memory / performance. I wonder if the navigation fw handles the construction / destruction of page objects more efficiently than what I did. I think the navigation FW works nicely with the browsers back and forward buttons - which my solution doesn't.
update 2: it looks as though teh C# applciation implments
public void InitializeComponent()
which loads and the XAML. Though I am no IL expert; I will make the similar changes on the F# side... I wonder if it is the partial class concept. One theory I am working on is:
page.xaml.cs is definitely a partial class - you can read it in the source.
page.xaml has an attribute that refers back to the c# class. I wonder if the special build commands treat this as a partial class - by parsing it and creating 1) any member component references 2) intialComponent() method which registers the page wherever it needs to be registered?
Update 1: After a nights sleep the problem can be stated more accurately as I have a 100% f# / silverlight implementation and am looking to use the built in Navigation components. C# creates page.xaml and page.xaml.cs um - ok; but what is the relationship at a fundamental level? How would I go about doing this in f#?
The applcuation is loaded in the default module, and I pull the XAML in and reference it from the application object. Do I need to create instances / references to the pages from within the application object? Or set up some other page management object with the proper name value pairs?
When all the Help of VS is stripped away - what are we left with?
original post (for those who may be reading replies)
I have a 100% silverlight 3.0 / f# 2.0 application I am wrapping my brain around. I have the base application loading correctly - and now I want to add the naigation controls to it.
My page is stored as an embedded resource - but the Frame.Navigate takes a URI. I know what I have is wrong but here it is:
let nav : Frame = mainGrid ? mainFrame
let url = "/page1.xaml"
let uri = new System.Uri(url, System.UriKind.Relative) ;
nav.Navigate uri
Any thoughts?
Have you tried making the Xaml a file in the project with a BuildAction of Content rather than an EmbeddedResource? Honestly, I've no clue if that works, but it might get packaged into the .xap that way, and then the relative uri might work. How would it work in a C# project? Try that.
EDIT
Aha, Dmitry's template appears to have this figured out. He has Xaml files with BuildAction of Resource, and then code like
type MainPage() as this =
inherit UserControl()
do
Application.LoadComponent(this,
new System.Uri("/SilverlightApplication3;component/Page.xaml",
System.UriKind.Relative))
let layoutRoot : Grid = downcast this.FindName("LayoutRoot")
do
()
to load it.