FSharp.ReactiveWpf 0.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package FSharp.ReactiveWpf --version 0.0.5
                    
NuGet\Install-Package FSharp.ReactiveWpf -Version 0.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharp.ReactiveWpf" Version="0.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FSharp.ReactiveWpf" Version="0.0.5" />
                    
Directory.Packages.props
<PackageReference Include="FSharp.ReactiveWpf" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FSharp.ReactiveWpf --version 0.0.5
                    
#r "nuget: FSharp.ReactiveWpf, 0.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FSharp.ReactiveWpf@0.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FSharp.ReactiveWpf&version=0.0.5
                    
Install as a Cake Addin
#tool nuget:?package=FSharp.ReactiveWpf&version=0.0.5
                    
Install as a Cake Tool

FSharp.ReactiveWpf

一个用于 F# 和 WPF 的响应式数据绑定库,提供类型安全且函数式的 UI 绑定解决方案。

基本数据绑定

open FSharp.ReactiveWpf.Binding
open System.Reactive.Subjects
open System.Reactive.Disposables

// 创建可观察数据源
let numberValue = new BehaviorSubject<float>(0.0)
let textValue = new BehaviorSubject<string>("Hello")
let boolValue = new BehaviorSubject<bool>(false)

// 创建 disposable 容器
let disposables = new CompositeDisposable()

// 绑定文本框(浮点数)
bindingNumberBox disposables numberValue myTextBox

// 绑定文本框(字符串)
bindingTextBox disposables textValue myStringTextBox

// 绑定复选框
bindingCheckBox disposables boolValue myCheckBox

// 绑定单选按钮组
let radioButtons = [| radio1; radio2; radio3 |]
bindingRadioButtonGroup disposables selectedIndex radioButtons

数字输入对话框

open FSharp.ReactiveWpf.TextBoxWindow

// 获取浮点数输入
let (window, getResult) = getFloat 0.0

if window.ShowDialog() = Nullable true then
    let result = getResult()
    printfn "用户输入: %f" result

// 获取整数输入
let (window, getResult) = getInt 42

if window.ShowDialog() = Nullable true then
    let result = getResult()
    printfn "用户输入: %d" result

API 参考

绑定函数

文本框绑定
  • bindingNumberBox - 浮点数文本框
  • bindingIntegerBox - 整数文本框
  • bindingInt64Box - 64位整数文本框
  • bindingTextBox - 字符串文本框
选择控件绑定
  • bindingComboBox - 组合框(索引绑定)
  • bindingComboBoxItem - 组合框(项绑定)
  • bindingRadioButtonGroup - 单选按钮组
切换控件绑定
  • bindingCheckBox - 复选框
  • bindingRadioButton - 单选按钮
文本显示
  • bindingRun - Run 文本元素绑定

对话框函数

  • getFloat - 获取浮点数输入
  • getInt - 获取整数输入
  • getInt64 - 获取64位整数输入

MediaPlayer.createPlaylistObservable

完整示例

open System.Windows
open FSharp.ReactiveWpf.Binding
open System.Reactive.Subjects
open System.Reactive.Disposables

type MainWindow() as this =
    inherit Window()
    
    let disposables = new CompositeDisposable()
    
    // 创建数据模型
    let temperature = new BehaviorSubject<float>(20.0)
    let name = new BehaviorSubject<string>("")
    let isActive = new BehaviorSubject<bool>(true)
    let selectedIndex = new BehaviorSubject<int>(0)
    
    do
        // 初始化 UI 组件
        this.InitializeComponent()
        
        // 绑定控件
        bindingNumberBox disposables temperature this.temperatureTextBox
        bindingTextBox disposables name this.nameTextBox  
        bindingCheckBox disposables isActive this.activeCheckBox
        bindingComboBox disposables selectedIndex this.categoryComboBox
        
    interface IDisposable with
        member this.Dispose() = disposables.Dispose()

设计理念

响应式编程

库基于观察者模式,使用 BehaviorSubject<T> 作为数据源,确保数据流的实时性和一致性。

资源管理

使用 CompositeDisposable 统一管理订阅,避免内存泄漏。

关注点分离

UI 逻辑与业务逻辑清晰分离,便于测试和维护。

贡献

欢迎提交 Issue 和 Pull Request!

许可证

GPLv3

MediaPlayer.createPlaylistObservable

函数签名

val createPlaylistObservable : 
    mediaPlayer:MediaPlayer -> 
    subject:IObservable<string[]> -> 
    IObservable<unit>

功能描述

创建一个响应式音频播放器,能够监听播放列表序列并自动按顺序播放其中的音频文件。当接收到新的播放列表时,会自动停止当前播放并开始新的播放列表。

参数说明

  • mediaPlayer : System.Windows.Media.MediaPlayer
    用于实际播放音频的媒体播放器实例

  • subject : IObservable<string[]>
    播放列表的观察序列,每次发射一个字符串数组,每个字符串代表一个音频文件的完整路径

返回值

返回一个 IObservable<unit>,表示播放过程的观察序列。主要用于订阅播放生命周期,实际播放是副作用。

使用示例

let mediaPlayer = new MediaPlayer()
let playlistSubject = new Subject<string[]>()

// 创建播放器观察序列
let playback = MediaPlayer.createPlaylistObservable mediaPlayer playlistSubject

// 订阅播放过程
use subscription = playback.Subscribe()

// 发送播放列表
playlistSubject.OnNext([|
    @"C:\audio\file1.mp3"
    @"C:\audio\file2.mp3" 
    @"C:\audio\file3.mp3"
|])
Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.9 30 1/16/2026
0.0.8 140 12/6/2025
0.0.7 196 12/4/2025
0.0.6 672 12/3/2025
0.0.5 260 11/30/2025
0.0.4 253 11/30/2025
0.0.3 251 11/30/2025
0.0.2 255 11/30/2025
0.0.1 180 11/27/2025

MediaPlayer