Reputation: 483
I am in the process of learning F# and find the FsEmptyWindowsApp that uses FsXaml really useful for throwing together a UI for f# system. One issue I just cannot seem to be able to overcome is opening a new window from my startup MainWindow.xaml. I have created a ChildWindow.xaml and created a type using XAML provider in FsXaml but when I
type MainView = XAML<"MainWindow.xaml", true>
type ChildWindow = XAML<"ChildWindow.xaml",true>
type MainViewModel() as self =
inherit ViewModelBase()
...
member x.NewChildWindowCommand =
new FunCommand ((fun action ->
let cw = ChildWindow()
cw.Root.Activate() |> ignore
),
(fun canExecute -> true))
I always get an error when I run the command stating "cannot locate resource ChildWindow.xaml", I have put it in the project above MainWindow.xaml with its own code behind and always get the, cannot locate resource error.
I have tried manually loading xaml using
Application.LoadComponent(new Uri("/<asseblyname>;component;/ChildWindow.xaml",UriKind.Relative))
but once again same error regarding cannot locate resource...
Any help and explanation as to how I should be using XAML type provider (FxXaml) in FsEmptyWindowsApp to open a new window would be greatly appreciated. alternatively if anyone knows how to do page navigation with FsXaml that would be very useful. I have downloaded the Demos and non of them seem to cover multi-paged/-windowed demos
Upvotes: 3
Views: 682
Reputation: 594
In FsXaml 2.x opening a new window can be done as:
type ChildWindow = XAML<"ChildWindow.xaml">
//somewhere in the code
ChildWindow().Show() //open, don't wait
ChildWindow().ShowDialog() //open and wait
Solution file ChildWindow.xaml
should have Build action set to 'Resource'.
Upvotes: 1
Reputation: 483
I figured out the issue, on the newly created xaml files you need to go into the properties and set build action to resource ... now everything works as expected, wish I had figured this out sooner as been evading me for weeks
Upvotes: 2