當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。