当前位置: 首页>>代码示例>>C#>>正文


C# Cell.Sample方法代码示例

本文整理汇总了C#中Cell.Sample方法的典型用法代码示例。如果您正苦于以下问题:C# Cell.Sample方法的具体用法?C# Cell.Sample怎么用?C# Cell.Sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cell的用法示例。


在下文中一共展示了Cell.Sample方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SLabel

        public SLabel(Cell<string> text)
        {
            Action<string> setText = t => this.Dispatcher.InvokeIfNecessary(() => this.Text = t);

            // Set the initial value at the end of the transaction so it works with CellLoops.
            Transaction.Post(() => setText(text.Sample()));

            // ReSharper disable once UseObjectOrCollectionInitializer
            List<IListener> listeners = new List<IListener>();
            listeners.Add(Operational.Updates(text).Listen(setText));

            this.listeners = listeners;
        }
开发者ID:Angeldude,项目名称:sodium,代码行数:13,代码来源:SLabel.cs

示例2: SButton

        public SButton(Cell<bool> enabled)
        {
            StreamSink<Unit> sClickedSink = new StreamSink<Unit>();
            this.SClicked = sClickedSink;
            this.Click += (sender, args) => sClickedSink.Send(Unit.Value);

            // Set the initial value at the end of the transaction so it works with CellLoops.
            Transaction.Post(() => this.IsEnabled = enabled.Sample());

            // ReSharper disable once UseObjectOrCollectionInitializer
            List<IListener> listeners = new List<IListener>();
            listeners.Add(Operational.Updates(enabled).Listen(e => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = e)));
            this.listeners = listeners;
        }
开发者ID:Angeldude,项目名称:sodium,代码行数:14,代码来源:SButton.cs

示例3: STextBox

        public STextBox(Stream<string> setText, string initText, Cell<bool> enabled)
        {
            base.Text = initText;

            List<IListener> listeners = new List<IListener>();

            StreamSink<int> sDecrement = new StreamSink<int>();
            Cell<bool> allow = setText.Map(_ => 1).OrElse(sDecrement).Accum(0, (b, d) => b + d).Map(b => b == 0);

            StreamSink<string> sUserChanges = new StreamSink<string>();
            this.SUserChanges = sUserChanges;
            this.Text = sUserChanges.Gate(allow).OrElse(setText).Hold(initText);

            TextChangedEventHandler textChangedEventHandler = (sender, args) =>
            {
                string text = base.Text;
                this.Dispatcher.InvokeAsync(() => sUserChanges.Send(text));
            };

            this.TextChanged += textChangedEventHandler;

            // Set the initial value at the end of the transaction so it works with CellLoops.
            Transaction.Post(() => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = enabled.Sample()));

            listeners.Add(setText.Listen(t =>
            {
                this.Dispatcher.InvokeAsync(() =>
                {
                    this.TextChanged -= textChangedEventHandler;
                    base.Text = t;
                    this.TextChanged += textChangedEventHandler;
                    sDecrement.Send(-1);
                });
            }));

            listeners.Add(Operational.Updates(enabled).Listen(e => this.Dispatcher.InvokeIfNecessary(() => this.IsEnabled = e)));

            this.disposeListeners = () =>
            {
                foreach (IListener l in listeners)
                {
                    using (l)
                    {
                    }
                }
            };
        }
开发者ID:Angeldude,项目名称:sodium,代码行数:47,代码来源:STextBox.cs

示例4: Integrate

 public static Cell<Signal> Integrate(Cell<Signal> sig, double initial)
 {
     Stream<Signal> sSig = Operational.Updates(sig);
     return sSig.Accum(sig.Sample().Integrate(initial), (n, o) => n.Integrate(o.ValueAt(n.T0)));
 }
开发者ID:Angeldude,项目名称:sodium,代码行数:5,代码来源:Signal.cs


注:本文中的Cell.Sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。