我需要能够在F#interactive中创建一个新的AppDomain,以便托管多个WPF应用程序.我在编译的F#应用程序中获得必要的功能没有任何问题,但由于某种原因使其在F#interactive中工作似乎不可能.
这是最简单的案例: -
#r "PresentationCore.dll"
#r "PresentationFramework.dll"
#r "System.Xaml.dll"
#r "WindowsBase.dll"
open System
open System.Threading
open System.Windows
type myClass() =
let domain = AppDomain.CreateDomain("another domain")
//this function starts a WPF app
let funct() =
let WPFStart() =
let app = Application()
let win = Window()
app.Run(win) |> ignore
let thread = Thread WPFStart
thread.IsBackground <- true
thread.SetApartmentState ApartmentState.STA
thread.Start()
do CrossAppDomainDelegate(funct) |> domain.DoCallBack
myClass();;
Run Code Online (Sandbox Code Playgroud)
我总是回过头来做些什么
System.Runtime.Serialization.SerializationException: Type is not resolved
for member 'FSI_0002+-ctor@24,FSI-ASSEMBLY, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null'.
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at …
Run Code Online (Sandbox Code Playgroud) 我想在TextBox中按"Enter"时开始动画.我没有找到合适的事件,所以我做了以下事情
XAML
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Window.Resources>
<Storyboard x:Key="testAnimation">
<BooleanAnimationUsingKeyFrames
FillBehavior="HoldEnd"
Storyboard.TargetName="txtB"
Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="00:00:00"
Value="False" />
</BooleanAnimationUsingKeyFrames>
<DoubleAnimation
Storyboard.TargetName="rtbl"
Storyboard.TargetProperty="Opacity"
From="0"
To="1"
Duration="0:0:2"
AutoReverse="True">
</DoubleAnimation>
<BooleanAnimationUsingKeyFrames
FillBehavior="HoldEnd"
Storyboard.TargetName="txtB"
Storyboard.TargetProperty="IsEnabled"
BeginTime="0:0:4"
>
<DiscreteBooleanKeyFrame KeyTime="00:00:00"
Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Name="rtbl" Opacity="0" HorizontalAlignment="Center" Margin="10" FontSize="30" Text="{Binding Text}"></TextBlock>
<TextBox Grid.Row="1" Name="txtB" IsEnabled="True" HorizontalAlignment="Center"
Margin="10" FontSize="30" Text="{Binding Input, UpdateSourceTrigger=PropertyChanged}" MinWidth="150"
>
<TextBox.InputBindings>
<KeyBinding Command="{Binding NextCommand}" Key="Enter"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
</KeyBinding>
</TextBox.InputBindings>
</TextBox>
</Grid> …
Run Code Online (Sandbox Code Playgroud) 在我的xaml
我有一个按钮和一个TextBlock
<TextBlock Text="{Binding AText}" FontSize="20"/>
<Button Content="Click" Command="{Binding MyCommand}" Grid.Row="1"/>
Run Code Online (Sandbox Code Playgroud)
在我的ViewModel中,我有以下代码
let aText = self.Factory.Backing(<@ self.AText @>, "Initial Text")
let asyncTask x = async {
self.AText <- "Loading"
do! Async.Sleep(5000)
self.AText <- "Loaded"
}
member self.AText with get() = aText.Value and set(v) = aText.Value <- v
member self.MyCommand = self.Factory.CommandAsyncChecked(asyncTask, fun _ -> true)
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,它会被禁用并保持不变,直到它完成asyncTask
.我认为设置canExecute
为true
将改变行为,但事实并非如此!
如何控制按钮的行为?
无法理解这种行为的原因:
let example count =
let arr = Array.create 2 (Array.zeroCreate count)
for i in [0..count - 1] do
arr.[0].[i] <- 1
arr.[1].[i] <- 2
arr
example 2 |> Array.iter(printfn "%A")
Run Code Online (Sandbox Code Playgroud)
打印:
[|2; 2|]
[|2; 2|]
Run Code Online (Sandbox Code Playgroud)
https://dotnetfiddle.net/borMmO
如果我更换:
let arr = Array.create 2 (Array.zeroCreate count)
Run Code Online (Sandbox Code Playgroud)
至:
let arr = Array.init 2 (fun _ -> Array.zeroCreate count)
Run Code Online (Sandbox Code Playgroud)
一切都会按预期工作:
let example count =
let arr = Array.init 2 (fun _ -> Array.zeroCreate count)
for i in [0..count - 1] do
arr.[0].[i] <- …
Run Code Online (Sandbox Code Playgroud) 有人可以告诉我如何在列表包含特定号码时过滤掉列表.例如,如果子列表包含2,那么我想要第三个值.
let p = [ [0;2;1]; [7;2;5]; [8;2; 10]; [44; 33; 9]]
//Filtered List: [1;5;10]
let q = p |> List.filter(fun((x,y):int List) (List.item 2 x) = 1, (List.item 3 y))
Run Code Online (Sandbox Code Playgroud)
上面是我的代码到目前为止.我知道它的错误,但似乎无法在代码中弄明白.
对不起,如果这看起来像一个愚蠢的问题,我仍然想弄清楚F#是如何做的
所以,说我建立了以下记录:
type person =
{ fName: string;
lName: string;
age: int;
weight: int; }
Run Code Online (Sandbox Code Playgroud)
然后我创建一些人来填充记录
let joe = {fName = "JOE"; lName = "QUAIL"; age = 34; weight = 133}
let jason = {fName = "JASON"; lName = "QUAIL"; age = 34; weight = 166}
let jerry = {fName = "JERRY"; lName = "PAIL"; age = 26; weight = 199}
Run Code Online (Sandbox Code Playgroud)
因此,我想要做的是至少需要两个或三个参数(比如age
,和lName
),我想通过搜索person
记录所有谁满足输入参数的人age
,并lName
与目标是将它们添加到列表中.所以在这个例子中,我想通过记录搜索姓氏"QUAIL"和34岁,这将得到我和乔和杰森
在F#中,我认为模式匹配是可行的方法,但我不知道如何实现模式匹配结构.
我的想法是使用这样的结构:
let myPeeps =
List.filter (function
| …
Run Code Online (Sandbox Code Playgroud) 我想在Suave中使用非拉丁符号,例如西里尔字母,但得到奇怪的结果
MCVE
open Suave
open Suave.Filters
open Suave.Operators
open Suave.Successful
let app =
choose [
GET >=> OK "??????, ???!"
]
startWebServer defaultConfig app
Run Code Online (Sandbox Code Playgroud)
结果
所以,Q是 - 如何解决它?
在本教程INotifyPropertyChanged
中模式-不是在视图模型.
这是正确和可接受的吗?什么是标准?