GithubHelp home page GithubHelp logo

fsprojects / fsxaml Goto Github PK

View Code? Open in Web Editor NEW
172.0 27.0 48.0 1.07 MB

F# Tools for working with XAML Projects

Home Page: http://fsprojects.github.io/FsXaml/

License: MIT License

Shell 1.78% F# 97.87% Batchfile 0.35%
fsharp xaml

fsxaml's Introduction

Issue Stats Issue Stats Build status License NuGet

FsXaml

F# Tools for working with XAML Projects

Maintainer(s)

The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)

fsxaml's People

Contributors

billhally avatar chrsteinert avatar dsyme avatar fsprojectsgit avatar johanlarsson avatar jschiefer avatar kevlut avatar nelak avatar reedcopsey avatar sergey-tihon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fsxaml's Issues

Runtime exception using C# library schema def for XAMl namespace declaration

HI Reed,

I'm using a third party C# charting library to create a sample app with F#. I get a runtime exception (at App.Root.Run() ) if I use the lib's schema definition from its AssemblyInfo, for the XAML namespace declaration . However, if I separately declare 4 library namespaces with xmlns, the sample runs fine. Are you aware of why this could occur?

Do we want a FunctionBindingExtension

Would be similar to FunctionExtension but enable binding to functions in the viewmodel.
Thinking something like:

MouseLeftButtonDown="{fsxaml:Handler {fsxaml:FunctionBinding onMouseLeftDown},
                                     {fsxaml:Function local:Map.mouseEventArgsToPoint}}"

Not sure about it, perhaps it is just api bloat.
It would rid us of the need for an IObserver<'t>/ICommand in the viewmodel.

downsides

  • API bloat
  • Will be hard to get intellisense or even validation as the providevalue method is not called in designtime. In the constructor there is not much context so not much we can do there, that I know.

Cannot build with latest version of FsXaml (v3.1.3)

An attempt to build an existing application that works with v.3.1.2 fails when upgraded to v.3.1.3. Using the demo application WpfMvvmAgent as an example, the compiler error messages are:

WpfMvvmAgent\MainWindow.xaml.fs(7,23): error FS3033: The type provider 'FsXaml.XamlTypeProvider' reported an error: The type initializer for 'FsXaml.EventToMailbox' threw an exception.

WpfMvvmAgent\MainWindow.xaml.fs(7,23): error FS3033: The type provider 'FsXaml.XamlTypeProvider' reported an error: The type initializer for 'FsXaml.EventToMailbox' threw an exception.

WpfMvvmAgent\MainWindow.xaml.fs(11,5): error FS0945: Cannot inherit a sealed type

"A strongly-named assembly is required"

using "F# Empty Windows App (WPF)" template (version 2.0) :
I create an new project and update all nuget packages.
I then get the error "A strongly-named assembly is required" on the type provider.
see images.
Is this a problem with my setup ? Is this something I can fix directly?

(using VS2015 update 3)
2017-03-16_174025
2017-03-16_173955

Generated type has an extra constructor that takes FrameworkElement as a parameter

Let's say I have
type MyUserControl = XAML<"MyUserControl.xaml",true>
UserControl has one constructor that takes no parameters. The new type, MyUserControl, will only have one visible constructor as far as Intellisense is concerned, but if you go through the type's ConstructorInfo, you will find another constructor that takes a single FrameworkElement as a parameter. Creating the element with this second constructor will cause the control to fail to render properly. I happened to find this issue because I was creating the control using Unity's resolve. It used the second constructor by default and the control failed to render.

OnUnloaded is not called in WindowViewController

Hello,
maybe I'm misunderstanding something, but it seems that the OnUnloaded callback is never called in ViewControllerBase.

I'm using FsXaml.Wpf 0.9.9.

I have a XAML like so (MainWindow.xaml):

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MainWindow;assembly=MyApp"
    xmlns:viewmodel="clr-namespace:ViewModels;assembly=MyApp"
    xmlns:fsxaml="http://github.com/fsprojects/FsXaml"
    fsxaml:ViewController.Custom="{x:Type local:MainWindowController}"
    WindowStyle="None" ResizeMode="NoResize" Background="Black">
...

and a ViewController like so:

/// Top-level container for all XAML elements.
type MainWindow = XAML<"MainWindow.xaml", true>

type MainWindowController() = 
    inherit WindowViewController<MainWindow> ()

    override __.OnInitialized _ =
        base.DisposeOnUnload(someDisposable)

    override __.OnLoaded view =
         // do something

    override __.OnUnloaded view =
         // do something

OnInitialized and OnLoaded are called when the window is created, but OnUnloaded is not called on exit, which means that disposeble objects added to DisposeOnUnload are never disposed.
In which case should OnUnloaded be called?
Thanks

Change Behaviors to custom MarkupExtensions

It'd be nice to move from Blend SDK behaviors to markup extensions to avoid the dependency on the Blend SDK.

Will need to investigate if this works in Windows Store or not, however, from my recollection, this isn't supported there. That would mean either using behaviors (as we are now) or attached properties for Windows Store apps.

Allow events to be handled from xaml

Right now, if you put in an event handler, you get a runtime error parsing the xaml.

We could, in theory, handle this. I think I could make the type provider handle everything, but I'm not sure how to get the proper event info out of the xaml schema context while parsing the sample.

For example, given <Button Click="HandleClick" />, I'm not sure how to determine during the xml parsing that Click is an event, and know it's specific type. If somebody wanted to try to figure that out, I think we could get the type provider to route that into a virtual method, allowing for xaml-defined, type safe event handlers to be written.

Create attached property versions of Behaviors

This would allow users to support some of the binding scenarios without having the Blend SDK dependency.

For many F# users, I think this would be preferable to using the behaviors. A simple markup extension for events that binds to a command with the same converter infrastructure would probably suffice.

Get editor warning but runtime is fine

Description

See the picture:

image

(I am using the newest 2.0.0, but it is report 0.9.9. I have no idea about this.)

However, Hit F5, everything is working fine.

Repro steps

  1. Setup a F# project,
  2. Install FsXaml 2.0 from Nuget
  3. Write some XAML and its corresponding .xaml.fs files.

Expected behavior

I should get type intellisense from VS.

Actual behavior

VS is complaining some error, no type intellisense. ๐Ÿ˜ž

Known workarounds

No idea.

Related information

  • Operating system: Windows 10
  • Branch: The version 2.0.0 from NuGet.
  • .NET Runtime, CoreCLR or Mono Version: 4.5.2
  • Performance information, links to performance testing scripts: N/A

Temporary files proliferate over time

Using FsXaml over a long period of time causes a large number of files to accumulate in the user's temporary directory (c:\users\you\appdata\local\temp). These files occur in pairs, such as tmp2733.tmp and tmp2733.dll, where the .tmp file is 0 bytes and the dll is an assembly created by FsXaml. These files are not cleaned up by Visual Studio, and eventually cause slowness in the editor and errors. I recently found over 100,000 such files on a single machine.

Binding to SelectedItem property of ComboBox throws XamlDuplicateMemberException

Description

Binding in XAML to SelectedItem or SelectedValue or SelectedIndex of a Combobox throws XamlDuplicateMemberException.

Repro steps

Create XAML with a ComboBox in which ItemSource and SelectedItem are bound to some model properties. E.g.
<ComboBox ItemsSource="{Binding AllItems}" SelectedItem="{Binding CurrentItem}" / >

ViewModel has properties defined as:

let items = [|"One"; "Two"|]
member this.AllItems with get() = items
member this.CurrentItem with get() = items.[1]

Expected behavior

No exceptions thrown. The combobox has two items with second item selected.

Actual behavior

Exception on creating instance of the view type defined as XAML<"View.xaml">:
System.Xaml.XamlDuplicateMemberException was unhandled
Message: An unhandled exception of type 'System.Xaml.XamlDuplicateMemberException' occurred in System.Xaml.dll
Additional information: 'SelectedItem' property has already been set on 'ComboBox'.

Known workarounds

Setting selected item using code-behind works as expected.

Related information

  • Operating system Windows 10 64 bit
  • .NET Runtime 4.5
  • FsXaml.Wpf v2.2.0
  • FSharp.ViewModule.Core v0.9.9.3

FsXaml 2.0 Beta

Please consider testing out the new prerelease of FsXaml 2.0, and leaving comments and ideas below.

NuGet package published at https://www.nuget.org/packages/FsXaml.Wpf/2.0.0-beta1

This release includes significant improvements to the generated code related to all XAML types. The containers and factories no longer exist - loading XAML files into a generated type is much more aligned with the results from C# code generation (with some differences, described below).

Major Changes

  • UserControl types no longer are wrapped within a ContentControl when loaded from XAML. The "root" of the visual tree is the control itself, which means better efficiency, but also eliminates some of the bugs present in the previous version of FsXaml.
  • Application and ResourceDictionary no longer use factories. The XAML<> provider creates the Application or Resource Dictionary subclass directly. This is a breaking change from previous version - for example, instead of App().Root.Run() you just do App().Run().
  • The IViewController and specific view controller classes have been removed. The ViewController types in previous versions were intended as a way to duplicate "code behind" style functionality. Since we now create types directly, and have flagged them as inheritable, you can write code behind directly in a subclass. Detailed examples exists in the demos. For an example, see: https://github.com/fsprojects/FsXaml/blob/master/demos/WpfSimpleMvvmApplication/MainView.xaml.fs#L5-L18
  • FrameworkElement types automatically load all named elements. The 2nd static parameter to the type provider has been removed, and is automatically treated as if it were true. Types without named elements do not create the accessors or incur extra overhead, as the type provider handles the checking internally.
  • ResourceDictionary types (and Application) no longer create elements for items by x:Key. You can create a resource dictionary, but need to access it as a dictionary (which is more aligned with C#).
  • Added Wpf module with utilites which allow for installation of synchronization context prior to creating the application. This is required if doing asynchronous work within types that are generated directly from the main windows

Breaking Changes

  • The factory type removal means removing the extra .Root from application and resource dictionaries.
  • ViewControllers no longer exist. Convert to using code behind directly.

Known Issues

  • Use of code behind from within the main, startup window does not work. The easy workaround is to create the main window in code, such as in this demo: https://github.com/fsprojects/FsXaml/blob/master/demos/WpfMvvmAgent/App.fs#L9-L10
  • Visual F# Power Tools will report erroneous errors when subclassing generated types from a type provider. Every use of code behind causes 3 errors to show up if Power Tools is enabled. (The compiler handles it fine, and doesn't report errors, but if power tools is enabled, you get 3 that show up after compile, and red squigglies in the editor.)

Tasks prior to 2.0 RTM

  • Report issue with Visual F# Power Tools and inherting from generated types
  • See what can be done about #24
  • Handle issue #34
  • Migrate supplied behaviors to attached properties Moved to future in #35
  • Remove dependency of Expression.Blend.Sdk
  • Optional: Ship behaviors as separate NuGet/Project? (Please comment on whether Blend support is important to you - or this may be dropped)

Please try the new package, and let me know of any issues, ideas, or improvements that need to happen prior to 2.0.

Thank you!
Reed

Unable to find the ResourceDictionary

Hi,

I have the following app.xaml

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Telerik.Windows.Controls.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

The Telerik,Windows.Controls.xaml is at the root folder and above the app.xaml. (The same app.xaml file has no problem in a C# project). however in Fsharp project fails with

System.Windows.Markup.XamlParseException occurred
Message: A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in FsXaml.Wpf.dll
Additional information: 'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '10' and line position '37'.

at App().Root.Run()

Am i missing something here? also tried to use the applicationreources.xaml from the the demo as a test. same error is produced.
environment
F#3.0
VS2013

X64 Compilation fails with an error

When compiling against an X64 cpu architecture library fsXaml fails with the following error.

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
        Title="MainWindow" Height="414" Width="535">
    <Grid x:Name="MainGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="247*"/>
            <ColumnDefinition Width="0*"/>
            <ColumnDefinition Width="270*"/>
        </Grid.ColumnDefinitions>
        <StackPanel HorizontalAlignment="Left" Height="25" Margin="0,359,0,0" VerticalAlignment="Top" Width="527" Grid.ColumnSpan="3" Orientation="Horizontal">
            <Button Content="Order Send" x:Name="OrderSend" Width="191" Height="25" VerticalAlignment="Bottom"/>
            <Button Content="Order Update" x:Name="OrderUpdate" Width="194"/>
            <Button Content="Order Cancel" x:Name="OrderCancel" Width="141"/>
        </StackPanel>
        <DataGrid x:Name="OrderGrid" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransformOrigin="-3.7,-3.231" Grid.ColumnSpan="3" Height="164" Width="517">
            <DataGrid.Columns>
                <DataGridTextColumn Header="id" Binding="{Binding id}"/>
                <DataGridTextColumn Header="qty" Binding="{Binding qty}"/>
                <DataGridTextColumn Header="status" Binding="{Binding status}"/>
                <DataGridTextColumn Header="execqty" Binding="{Binding execqty}"/>
            </DataGrid.Columns>
        </DataGrid>
        <Label Content="Symbol" HorizontalAlignment="Left" Margin="0,169,0,0" VerticalAlignment="Top" Height="30" Width="58"/>
        <TextBox x:Name="Symbol" HorizontalAlignment="Left" Height="23" Margin="101,169,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="141"/> 
        <RadioButton x:Name="Buy" Content="Buy" HorizontalAlignment="Left" Margin="10,204,0,0" VerticalAlignment="Top" GroupName="buysell"/>
        <RadioButton x:Name="Sell" Content="Sell" HorizontalAlignment="Left" Margin="101,204,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.296,0.312" GroupName="buysell"/>
        <Label Content="Quantity" Grid.Column="2" HorizontalAlignment="Left" Margin="7,169,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1,0.5"/>
        <TextBox x:Name="Quantity" Grid.Column="2" HorizontalAlignment="Left" Height="23" Margin="84,169,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="181"/>
        <TextBox x:Name="Account" Grid.Column="2" HorizontalAlignment="Left" Height="23" Margin="84,204,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="181"/>
        <Label Content="Account" Grid.Column="2" HorizontalAlignment="Left" Margin="10,202,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.553,-0.346" Width="53"/>
        <RadioButton x:Name="Market"  Content="Market" HorizontalAlignment="Left" Margin="10,243,0,0" VerticalAlignment="Top" GroupName="ordertype"/>
        <RadioButton x:Name="Limit" Content="Limit" HorizontalAlignment="Left" Margin="101,243,0,0" VerticalAlignment="Top" d:IsHidden="True" GroupName="ordertype"/>
        <Label Content="Price" Grid.Column="2" HorizontalAlignment="Left" Margin="10,241,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="Price" Grid.Column="2" HorizontalAlignment="Left" Height="23" Margin="84,243,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="181"/>
        <Label Content="XML Config" HorizontalAlignment="Left" Margin="0,273,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="Config" HorizontalAlignment="Left" Height="23" Margin="101,273,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="322" Grid.ColumnSpan="3"/>
        <Button x:Name="Init" Content="Init Fmwk" Grid.Column="2" HorizontalAlignment="Left" Margin="176,271,0,0" VerticalAlignment="Top" Width="89"/>
    </Grid>
</Window>
open System
open System.Windows
open System.Windows.Controls
open FsXaml
open System.Xml
open System.Collections.Generic

type  Mainwindow = XAML<"gui.xaml">
[<STAThread>]
    try
        Application().Run( new Mainwindow() ) |> ignore

------ Build started: Project: atfgui, Configuration: Debug Any CPU

    C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\fsc.exe

-o:obj\Debug\atfgui.exe -g --debug:full --noframework --define:DEBUG
--define:TRACE --doc:bin\Debug\atfgui.XML --optimize- --tailcalls-
--platform:x64 -r:C:\Dev\ATF\assembly\Debug\frameworkevents.dll
-r:C:\Dev\ATF\tp\FsXaml\Debug\FsXaml.Wpf.dll
-r:C:\Dev\ATF\tp\FsXaml\Debug\FsXaml.Wpf.TypeProvider.dll
-r:C:\Dev\ATF\assembly\Debug\hostengine.dll
-r:C:\Dev\ATF\assembly\Debug\mktdataservices.dll
-r:C:\Dev\ATF\assembly\Debug\mktdatastructs.dll -r:"C:\Program Files
(x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\mscorlib.dll"
-r:C:\Dev\ATF\assembly\Debug\persistence.dll -r:"C:\Program Files
(x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\PresentationCore.dll"
-r:"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\PresentationFramework.dll"
-r:"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Core.dll"
-r:"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\System.dll"
-r:"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Numerics.dll"
-r:C:\Dev\ATF\framework\examples\atfgui\packages\Expression.Blend.Sdk.1.0.2\lib\net45\System.Windows.Interactivity.dll
-r:"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Xaml.dll"
-r:"C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Xml.dll"
-r:C:\Dev\ATF\assembly\Debug\tradingclasses.dll -r:"C:\Program Files
(x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\WindowsBase.dll"
--target:exe --warn:3 --warnaserror:76 --vserrors
--validate-type-providers --LCID:1033 --utf8output --fullpaths
--flaterrors --subsystemversion:6.00 --highentropyva+
--sqmsessionguid:ed3396d7-c111-4f7c-91a2-bf3691c7001c
"c:\temp.NETFramework,Version=v4.5.AssemblyAttributes.fs" atfgui.fs
FSC: error FS3031: The type provider
'C:\Dev\ATF\tp\FsXaml\Debug\FsXaml.Wpf.TypeProvider.dll' reported an
error: Assembly attribute 'TypeProviderAssemblyAttribute' refers to a
designer assembly 'FsXaml.Wpf.TypeProvider' which cannot be loaded or
doesn't exist. Could not load file or assembly
'file:///C:\Dev\ATF\tp\FsXaml\Debug\FsXaml.Wpf.TypeProvider.dll'; or
one of its dependencies. An attempt was made to load a program with an
incorrect format.
FSC: warning FS3005: Referenced assembly
'C:\Dev\ATF\tp\FsXaml\Debug\FsXaml.Wpf.TypeProvider.dll' has assembly
level attribute
'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute'
but no public type provider classes were found
Done building project "atfgui.fsproj" -- FAILED.

Build FAILED.

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped

Object reference not set to instance of object assigning Name for UserControl

Description

Object reference not set to instance of object when assigning Name or x:Name to a UserControl used from a separate Window.

If I can provide any further information, please let me know! I'm happy to help.

Repro steps

  1. Edit demos/WpfSimpleMvvmApplication/MainWindow.xaml line 12 to read as follows:

    <local:MainView Grid.Row="1" IsTabStop="False" x:Name="MyMainView" />
    or
    <local:MainView Grid.Row="1" IsTabStop="False" Name="MyMainView" />

  2. Compile

Expected behavior

Assignment of a name+property for the UserControl so that it can be referenced from code. This does appears to work for tbFullName and FirstName in MainView.xaml.

Actual behavior

error FS3033: The type provider 'FsXaml.XamlTypeProvider' reported an error: Object reference not set to an instance of an object.

Related information

FsXaml (3.1.2) and head of master (commit 9fc1da3)

XAML fails to load at run-time if it's in a sub-folder

If the target XAML file is located in a sub-folder, it can be accessed at compile-time, but not at run-time.

type MyView = FsXaml.XAML<"Views\MyView.xaml">

Error message: The specified resource name "views\myview.xaml" does not exist in the resource file.

UserControl data binding regression in 2.0.0

Description

Binding the DataContext of a UserControl using an ElementName binding worked in 0.9.9, does not work in 2.0.0

Repro steps

MainWindow.xaml

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:ViewModels;assembly=FsEmptyWindowsApp1">
    <StackPanel>
        <TextBox Name="Foo"/>
        <local:TestControl DataContext="{Binding ElementName=Foo, Path=Text}"/>
    </StackPanel>
</Window>

TestControl.xaml

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <TextBox Text="{Binding .}"/>
</UserControl>

Expected behavior

Typing into the TextBox Foo results in the same text in the TestControl.

Actual behavior

TestControl is blank. Binding error in Debug Output is

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=Foo'. BindingExpression:Path=Text; DataItem=null; target element is 'TestControl' (Name=''); target property is 'DataContext' (type 'Object')

Known workarounds

None.

Related information

  • Windows 8.1
  • FsXaml 2.0.0 via nuget
  • .NET 4.5

How to build a suggestion list?

I'd like to implement a "rename suggestion list" for https://github.com/fsprojects/VisualFSharpPowerTools/blob/master/src/FSharpVSPowerTools.Logic/RenameDialog.fs#L16 but don't really know how to do something like this with FsXaml. I'd like to provide a list with suggestions to the new name textbox (https://github.com/fsprojects/VisualFSharpPowerTools/blob/master/src/FSharpVSPowerTools.Logic/RenameDialog.xaml#L52) and if the user selects one of these the I want to have it in the textbox.
Can you give me a hint?

A case where XAML event is not found

Description

There was no handler to override when the XAML looked like this.

<MenuItem Header="{Binding Source={x:Static lang:Resources.Exit}}" Click="MnExitClick"/>

The error message from the compiler was: "No abstract or interface member was found that corresponds to this override."

type MainWindowXaml = XAML<"Xaml/MainWindow.xaml">

type MainWindow() =
    inherit MainWindowXaml()
    override x.MnExitClick (o, e) = x.Close()

Known workarounds

I moved the handler declaration to the front, like this, and then it compiled and ran successfully.

<MenuItem Click="MnExitClick" Header="{Binding Source={x:Static lang:Resources.Exit}}"/>

Related information

Windows 10. VS 2015 with Update 3. NET Framework 4.5.2. FsXaml 3.1.6.

Type mismatch of XamlResourceAccessor when working with ResourceDictionary

I try to build a XamlProvider on a ResourceDictionary file: type MyResourceDictionary = XAML<"MyResourceDictionary.xaml", true>

After I compile the project, the following error appears:

The type provider 'FsXaml.XamlTypeProvider' reported an error: Type mismatch when splicing expression into quotation literal. The type of the expression tree being inserted doesn't match the type expected by the splicing operation. Expected 'FsXaml.XamlResourceAccessor', but received type 'FsXaml.XamlResourceAccessor'. Consider type-annotating with the expected expression type, e.g., (%% x : string) or (%x : string).

If I remove the true parameter, it compiles, but the whole point of creating a provider gets lost. Here is a sample project.

P.S. Win7 x64 + VS 2013 Community SP4 + F# 3.1

XAML Node Stream: Missing CurrentObject before EndObject

Description

Creating a new Window which has a PNG image in it - I've tried as both Icon of the window or as a background image on a child control. The image is a content resource and shows in the WPF designer - but when I run the application, as soon as I create the window, I get: -

An unhandled exception of type 'System.Xaml.XamlObjectWriterException' occurred in System.Xaml.dll Additional information: XAML Node Stream: Missing CurrentObject before EndObject.

Any way I can get around this?

VS 2017 message box when opening XAML file: Visual Studio has encountered an unexpected error.

When I try to open a XAML file in VS 2017 on this particular machine, it won't open. If I double click the file in Solution Explorer, nothing at all happens. If I left-click and select Open, then this dialog box appears with the message "Visual Studio has encountered an unexpected error.", and that's all.

It happens with any XAML file in any project, and it only happens on this one machine. For this reason I don't see much use in supplying a repro, but I'll do that on request. I have another machine with what should be exactly the same setup, and there's no problem there. I also have other machines, and there's no problem with them either.

I am quite certain it used to work several weeks back, and I think the problem occurred now and then for some weeks, and now it's not possible at all to open XAML files.

Is this a problem with FsXaml, VS, F#, or ... ?

I do anticipate a reinstall of something will fix the problem, but first I'd rather contribute to fixing the bug if possible. With so little to go on, and the problem only on this machine, maybe I should just ignore and reinstall.

Known workarounds

I have to use VS 2015 or another machine to edit XAML.

Related information

FsXaml.Wpf 3.1.6 and 3.1.2
.NET Framework 4.5.2
Visual Studio 2017, v 15.2 (26430.14)
F# 4.0 (4.4.0.0)
F# Nightly builds 15.4.1.17062201
Windows 10

EventToMailbox does not work with MailboxParameter

I was trying to use the EventToMailbox trigger so that I could process an item associated with the button in a mailbox. I used databinding to link the MailboxParameter to the DataContext of the current item of the ItemsControl.
After wiring everything up, nothing happened on the button click. I noticed every time I clicked the button, debug output would show a System.ArgumentException had occurred. I set the debugger to break on said exception, and I saw the details of the exception was that (paraphrasing) a Tuple<object,bool> cannot be applied to a method which takes a ChildViewModel parameter. I also saw on the call stack FsXaml.Wpf.Blend.dll!FsXaml.EventToMailbox.Invoke(object param), so I looked at the code and found

let getParameter (param : obj) =
match self.MailboxParameter, self.PassEventArgsToMailbox with
| (null, true) -> self.EventArgsConverter.Convert (param :?> EventArgs) self.EventArgsConverterParameter
| param -> param :> obj
. I believe the problem is specifically with the last line, | param -> param :> obj , as this wraps the MailboxParameter with the status of whether to pass EventArgs to the mailbox as a tuple, rather than just the MailboxParameter itself. Rather, the code should either be | param, _ -> param :> obj or | _ -> this.MailboxParameter.

Can't build x64 Solution config with FsXaml in an x64 app, and x64 library

If you create a Xaml app using FsXaml, referencing a separate library, and set their build configurations and flags to x64, then building the solution fails with these errors:
parse error FS3053: error : The type provider constructor has thrown an exception: Could not load file or assembly 'Testx64Library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. This assembly was compiled for a different processor.

FSC: warning FS3005: Referenced assembly '...\Projects\FsXamlx64Test\packages\FsXaml.Wpf.0.9.9\lib\net45\FsXaml.Wpf.TypeProvider.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found

Suggestion: alternative way to wrap XAML(?)

I've developed my own XAML wrapper in F#. It makes implementing User Control in F# more easier (is there a way to do it with FsXaml type provider?). My wrapper looks like this:

// instead of type MainWindow = XAML<"Sample.xaml">
type MainWindow() as me =
  inherit Window()
  do me.InitializeCodeBehind("Sample.xaml")

(For full example, see https://github.com/ruxo/WpfFs/blob/master/README.md )

Is this feature interested enough to put in FsXaml library?

(Sorry if this style has been discussed before, I'm new to FsXaml library)

v0.9.9 somehow tries to do something with v0.9.8

When using the current FsXaml version (both from the NuGet package as well as source-built assemblies) in a project, I get an error on the line

type App = FsXaml.XAML<"App.xaml">

saying

The type provider 'FsXaml.XamlTypeProvider' reported an error: Could not load type 'FsXaml.XamlResourceFactory' from assembly 'FsXaml.Wpf, Version 0.9.8.0, Culture=neutral, PublicKeyToken=null'.

I can't imagine how it would get the idea to look for 0.9.8 when both assemblies are 0.9.9. For lack of any better ideas, I have tried adding a binding redirect to 0.9.9, but to no avail.

All projects use the 4.5 runtime and F# 3.1. The demo project for FSharp.Desktop.UI in the FsXaml repository works fine.

Any ideas? Am I missing something?

FsXaml for UserControls

I've been attempting to find a way to use FsXaml to access a UserControl that's defined in its own individual XAML file, but I've been unable to find a method that works.

For example when "ListBoxQuery.xaml" defines a UserControl

 type ListBoxQueryXaml    = XAML<"ListBoxQuery.xaml">
 let queryUI              = new ListBoxQueryXaml()
 let usercontrol          = ListBoxQueryXaml.Accessor(xamlui)

is the only way I've been able to access the elements defined in the XAML file, but this method fails because at runtime attempting to use the elements throws a null object exception.

When these types like ListBoxQueryXaml are compiled to a class library and that .dll is loaded into the XAML Designer by adding it to the toolbox it does create XAML elements that can be embedded into other windows and panels. Although this isn't particularly useful as I haven't been able to give them any functionality using F# code beyond the default behavior of their standard control subcomponents.

I've had great success using FsXaml for individual WPF GUI windows, but perhaps I have a fundamental misunderstanding of how it should be applied in the creation of custom controls?

Windows Store

Hi,

On your presentation you mentioned you started also on a Windows Store version.
Can you publish that on github also?

Change to MIT License

I'd like to change this project from Apache to MIT licensing, in order to be the least restrictive possible.

I've tried to go through the commit list, and checked for all contributors who have contributed code to the project itself, which still exists in some form or another.

Would you all please comment here that you either agree, or let me know why you object, so we can re-license this in a future release?

Thank you,
Reed

People who have contributed code which still exists in some form:

Include Item and Project Templates

I would be nice to include a set of item and project templates in a vsix which could be installed.

This would replace the community templates (which are horribly out of date) with FsXaml specific templates.

Can't build x64 Solution config with FsXaml in an x64 app, and x64 library (v2)

Description

If you create a Xaml app using FsXaml, referencing a separate library, and set their build configurations and flags to x64, then building the solution fails with this error:
parse error FS3053: error : The type provider constructor has thrown an exception: Could not load file or assembly 'Testx64Library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. This assembly was compiled for a different processor.

Repro steps

Build the x64 configuration of the project at https://github.com/marklam/bugrepro-fsxaml-19
This includes a ViewModel assembly set to x64, and an app set to x64

Expected behavior

A working (but empty) app, as seen when building 'Any CPU'

Actual behavior

parse error FS3053: error : The type provider constructor has thrown an exception: Could not load file or assembly 'Testx64Library, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. This assembly was compiled for a different processor.

FSC: error FS2024: Static linking may not use assembly that targets different profile

Description

Build error: FSC: error FS2024: Static linking may not use assembly that targets different profile with OxyPlot example and FsXaml when using VS2015 Update 2. .NET 4.6.x. I attached the VS project.
SimpleDemoFsharp (2).zip

Repro steps

Program.fs:

open System
open System.Windows
open FsXaml

// Comment out to build:
type MainWin = XAML<"MainWindow.xaml">

[<STAThread>]
[<EntryPoint>]
let main argv = 
    // Comment out to build:
    let app = Application()
    let win = MainWin()
    app.Run win    

MainViewModel.fs:

namespace SimpleDemoFsharp

open OxyPlot
open OxyPlot.Series

type MainViewModel() =
    let myModel = PlotModel()
    //comment below to build an empty window with FSXAML:
    do
        myModel.Series.Add(FunctionSeries(cos, 0.0, 10.0, 0.1, "cos(x)"))
    member mainWindow.MyModel with get() = myModel

XAML:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
    xmlns:local="clr-namespace:SimpleDemoFsharp;assembly=SimpleDemoFsharp"

    Title="OxyPlot in F# and WPF" Height="480" Width="640">
    <Window.DataContext>
        <local:MainViewModel/>
    </Window.DataContext>
    <Grid>
        <oxy:PlotView Model="{Binding MyModel}"/>
    </Grid>
</Window>

Expected behavior

Show oxyplot plotmodel when using FSXAML.

Actual behavior

When loading the XAML directly, oxyplot creates the chart.
When loading the XAML via FSXAML, the project won't build.
When uncommenting the myModel.Series.Add(FunctionSeries(cos, 0.0, 10.0, 0.1, "cos(x)")) line the project compiles.

Return type for Converter<'a,'b> is too strict

On a WPF project. I have a ValueConverter that is bound to a TextBlock. It takes in the object (lets say of type Thing) that is bound to TextBlock and returns a decimal figure. The TextBlock binds to a String, but my converter returns a Decimal value.

If I create a Converter<Thing, Decimal>, the converter will always fail because the return types are not compatible i.e. Decimal and String (inside the fWrapped function). I have to change my converter to return a string and explicitly ToString() the decimals.

In another case I also had a converter that returns a SolidColorBrush, yet the destination control expected just a Brush. So again I had to cast them to that.

I don't want to have to worry about the output type to be honest - I want to be able to return decimals and let WPF decide how to render it.

Sign FsXaml.Wpf assembly

Hi,
Thanks for the awesome library!

Description

Unable to load FsXaml.Wpf assembly from signed VSIX project.

This is the message from the original exception:
"Could not load file or assembly 'FsXaml.Wpf, Version=3.1.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)"

Known workarounds

Do not sign VSIX project. In this case everything works fine, exception is gone.

Would it be possible to sign the assembly?

--
Kirill

Error in XAML type provider : Could not load type ...

Description

I upgraded FsXaml.Wpf from 2.2.0 to 3.1.1 and this error happened:

fsxaml_error

I used NuGet package manager in Visual Studio and just clicked 'Update'.

Related information

  • Operating system: Windows 7
  • IDE: Visual Studio 2015 pro
  • .NET: 4.61 and F# runtime 4.4.0.0

UserControl Focusable

UserControls created via the provider are focusable whereas normal UserControls are not. This is not desired behavior in my current project so I've worked around it by adding a Blend behavior to each of my UserControls, but it would be nice if this wasn't necessary. A little troubleshooting: the provided type for UserControls is inheriting from ContentControl which seems to default its Focusable property to true. UserControl also inherits from ContentControl, but seems to default Focusable to false.

The demos do not come with FsXaml.Wpf, FsXaml.Wpf.Blend and Fsharp.ViewModule.Core installed

As the title says. As a newbie to this, it was not immediately obvious what those 50 build errors meant. I had to compare it with the F# WPF template to figure out what is wrong. In addition to that the FSharpDesktopUINumericUpDown demo needs Fsharp.Desktop.UI as well. It might be good to have the necessary packages be automatically downloaded.

The FsXaml project in general needs some documentation for it.

Input String was not in correct format

Description

"Input String was not in correct format" when creating a new project with FsXaml template.

Repro steps

  1. Searched for "FsXaml" via template selection and installed it, checked it via "Extensions and updates";
  2. New Project, choose "F# Empty Windows App (WPF)";
  3. Change folder and filename;
  4. Click "OK".

Expected behavior

Creates new, empty F# WPF project

Actual behavior

Creates the solution folder and sub-folder, but does not create any files. Displays alert message "Input String was not in correct format".

Known workarounds

Related information

  • OS: Windows 10
  • .NET Runtime: Selected 4.5.2
  • Visual Studio 2015 Community Edition, v14.0.25424.00 Update 3

Error from TypeProvider

I got this error:

Could not load type 'FsXaml.XamlContainer' from assembly 'FsXaml.Wpf, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'.

I used the yo fsharp generator to start my project as a standalone project.

Support using from FSI

FsXaml supports only loading the XAML files from a resource. It would be good if we could just load directly a XAML file from the current directory so we could use it on FSI

simplifying XAML type provider

Why XAML Type Provider cannot generate a root type that erases to System.Windows.Window and for every visual element has provided property of appropriate type (Button, TextBox etc)?
Design with CreateRoot`` factory method and nestedAccessor``` seems non-intuitive and redundantly complex.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.