Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:33:23+00:00 2026-05-14T22:33:23+00:00

Wondering how to accomplish setting the Style xaml with the code in F#. The

  • 0

Wondering how to accomplish setting the Style xaml with the code in F#. The code is simple enough:

this.DefaultStyleKey <- typeof<MyControl>

In a C# project the build options allow you to mark the XAML as a resource custom build command of: MSBuild:Compile

I don’t see it in the properties panel, so I tried to add it by hand to the project file myself…

Any ideas? The application loads – the custom control has no output (but the code executes).

Thanks

UPDATE:

I checked the manifests and the resource was included as expected between my project and the project I am porting… Looking for a next step.

UPDATE 2:

Well it may be included in the manifest OK – but it is not being “compiled” as the C# version of the project throws an error in the build process when I malform the XML while the F# version allows the malformed XML to be brought into the application.

UPDATE 3:

Loading the XAML is fine now (i guess) however I am having some issues with the properties of the control:

 static member ItemsProperty : DependencyProperty = 
        DependencyProperty.Register(
            "Items",
            typeof<MyMenuItemCollection>,
            typeof<MyMenu>,
            null);

 member this.Items
        with get () : MyMenuItemCollection = this.GetValue(MyMenu.ItemsProperty) :?> MyMenuItemCollection
        and set (value: MyMenuItemCollection) = this.SetValue(MyMenu.ItemsProperty, value);

The problem occurs on access:

for menuItem in this.Items do
    let contentElement: FrameworkElement = menuItem.Content

where I get a null pointer exception on this.Items; however I have it initialized in the constructor:

do
    this.Items <- new CoolMenuItemCollection()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:33:24+00:00Added an answer on May 14, 2026 at 10:33 pm

    The C# style of compilation of XAML files is not supported by the F# tools for Visual Studio, so there is no way to get the same behavior as in C#. I think you have two options:

    • Create a C# project with XAML files and reference F# library which implements the core functionality (or reference C# library from F# and load user interface from the C# library in your F# application)

    • Use XamlReader object (see MSDN) and load the XAML file (embedded in resources in the simple way) programmatically. You won’t get any of the C#-compiler generated features (e.g. named properties for all objects with x:Name), but otherwise, it should work in the usual way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there was a way to accomplish this, or if there
I was wondering what would be the best way to accomplish something like this...
I'm wondering what you think of the several methods there are to accomplish this:
Recently, I'm trying to write a simple OS. This is a big project. when
I'm wondering how one could use template databinding to accomplish what the following code
I am using Django and I am wondering how I can accomplish this. It
I'm wondering if anyone knows how to accomplish the following: Let's say I have
I am looking to accomplish the following and am wondering if anyone has a
I was wondering if anyone could tell me if what I'm trying to accomplish
Let's say that I'm setting up an upload feature for a project. I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.