小编Tat*_*ice的帖子

傻F#\ WPF错误 - "名称'abc'在命名空间'xyz'中不存在",即使Intellisense看到它

尝试从C#迁移到F#(我第一次使用MVC而不是MVVM,所以我的术语可能已关闭),但最终我无法设置我的WPF\XAML DataContext,因此我可以绑定我的UI.

我有以下简单的WPF:

<UserControl x:Class="epic.Sandbox.Controls.FieldController"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:epic.Sandbox.Controls"
             xmlns:Views="clr-namespace:epic.View;assembly=epic.Core"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.DataContext>
        <Views:TextFieldModel />
    </UserControl.DataContext>
    <Grid>

    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

和以下F#:

namespace epic.View

open System
open FSharp.Desktop.UI

[<AbstractClass>]
type public FieldModelBase() = 
    inherit Model() 

    let mutable fieldCaption: string = null
    let mutable fieldValue: System.Object = null
    [<DerivedProperty>]
    member this.Caption with public get() = sprintf "%s" fieldCaption and set value = fieldCaption <- sprintf "%s" value; this.NotifyPropertyChanged "Caption"
    [<DerivedProperty>]
    member this.Value with public get() = fieldValue and set value = …
Run Code Online (Sandbox Code Playgroud)

wpf model-view-controller xaml f#

5
推荐指数
1
解决办法
165
查看次数

F#中是否存在C#和VB兼容的System.Void*?(关闭指向非托管Alloc的指针?)

    [<DllImport("kernel32")>]
    extern bool CloseHandle(System.Void* handle);
    //System.Void also throws same error
    //extern bool CloseHandle(System.Void handle); 
Run Code Online (Sandbox Code Playgroud)

给出错误:

'System.Void'只能在F#中用作'typeof'

    extern bool CloseHandle(typeof<System.Void> handle);
Run Code Online (Sandbox Code Playgroud)

不编译.同样的错误,

"System.Void只能用作...的类型"

F#void*确实编译

    extern bool CloseHandle(void* handle);
Run Code Online (Sandbox Code Playgroud)

但在C#中使用它会引发设计时转换错误

public void CloseBeforeGarbageCollection(IntPtr someAllocIntPtr)
{
    //test unmanaged block
    var result = CloseHandle(someAllocIntPtr.ToPointer());
    return result;
}
Run Code Online (Sandbox Code Playgroud)

'无法从'void*'转换为'System.IntPtr'

虽然传递托管的IntPtr将编译

//test managed IntPtr
var result = CloseHandle(someAllocIntPtr); //throws error at runtime
Run Code Online (Sandbox Code Playgroud)

但是当someAllocIntPtr结果是Marshal.AllocHGlobal,它会抛出一个运行时异常External component has thrown an exception..据我所知,发生这种情况是因为someAllocIntPtr(作为Marshal.AllocHGlobal的结果)在技术上是一个非托管指针的托管指针,与普通的IntPtr不同.Peter Ritchie在回答他的答案时注意到这一点:System.Runtime.InteropServices.SEHException(0x80004005):外部组件抛出异常

避免此运行时异常的唯一方法是将句柄包装在SecureHandle()子类中,但我认为这违反了ref-ref\out-outMSDN上的规则: …

c# vb.net f# interop kernel32

5
推荐指数
1
解决办法
266
查看次数

F# 中的强命名资源

按照这篇文章中提供的步骤,我已经成功添加了一个资源文件,并且可以查询我包含的资源,但我必须手动使用该类ResourceManager来获取嵌入的资源 - 例如

let someText = ResourceManager("strings", System.Reflection.Assembly.GetCallingAssembly()).GetObject("SomeText")
Run Code Online (Sandbox Code Playgroud)

在 VB.NET 和 C# 中,这些资源是强命名的。因此,如果我有一个名为“SomeText.txt”的资源文件,我可以在代码中调用它

var someText = MyDefaultNamespace.Properties.Resources.SomeText;
Run Code Online (Sandbox Code Playgroud)

有没有办法让 F# 资源像 C# 和 VB.NET 中那样在 F# 中进行强命名?也许是 t4 文本模板?

f# resx

5
推荐指数
1
解决办法
591
查看次数

类库中的可移植 XAML 样式

所以我有一个应用程序,其样式直接放入 App.xaml 文件中,如下所示:

<Application x:Class="Test.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Startup="OnStartup">
    <Application.Resources>
        <Style x:Key="SpecialButtonStyle" TargetType="Button">
            <Setter Property="Content" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" />
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
            <Setter Property="BorderThickness" Value="2" />
            <Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
            <Setter Property="Foreground" Value="White" />
            <Setter Property="Block.Foreground" Value="White" />
            <Setter Property="TextBlock.Foreground" Value="White" />
            <Setter Property="TextElement.Foreground" Value="White" />
            <Setter Property="FontWeight" Value="Bold" />
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="False">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Border Background="{TemplateBinding Background}" Padding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness}">
                                    <Border Background="{TemplateBinding BorderBrush}"> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml portability visual-studio

4
推荐指数
1
解决办法
1805
查看次数

TSQL XML - 在Cross Apply上过滤节点LIKE'x'

使用以下XML:

<Path>
    <To>
        <Value>
            <Array>
                <NumberDecimal>10.0</NumberDecimal>
                <TextEnglish>Ten</TextEnglish>
                <NumberRomanNumeral>X</NumberRomanNumeral>
            </Array>
        </Value>
    </To>
</Path>
Run Code Online (Sandbox Code Playgroud)

如何过滤以下交叉应用于所有/仅Number***xml节点?

SELECT child.value('concat(local-name(.),": ",.)', 'varchar(max)') AS [value]
FROM imports i
CROSS APPLY i.import_data.nodes('/Path/To/Value/Array/*[local-name(.) = ''NumberDecimal'']') AS nodes(child)
Run Code Online (Sandbox Code Playgroud)

收益:

NumberDecimal:10

需要这样:

SELECT child.value('concat(local-name(.),": ",.)', 'varchar(max)') AS [value]
FROM imports i
CROSS APPLY i.import_data.nodes('/Path/To/Value/Array/*[local-name(.) = ''Number/*'']') AS nodes(child)
Run Code Online (Sandbox Code Playgroud)

需要退货:

NumberDecimal:10

NumberRomanNumeral:X

但它什么也没有回报....

xml t-sql sql-server nodes

3
推荐指数
1
解决办法
617
查看次数

XAML路径 - 在不使用弧的情况下绘制圆

在WPF应用程序中,我知道我可以使用以下路径语法绘制一个Circle:

<Path
    Stretch="Fill"
    StrokeThickness="1"
    Data="M -1,0 A 1,1 0 1 1 1,0 M -1,0 A 1,1 0 1 0 1,0" />
Run Code Online (Sandbox Code Playgroud)

但是,我正在使用一个尚不支持Arcs的编译器(C#和XAML for HTML5).

如何在不使用Arcs的情况下绘制此圆圈?解决方案是逐点绘制 - 基本上是六角形,给予还是采取?

wpf xaml

0
推荐指数
1
解决办法
1281
查看次数