# å¤æ´å±¥æ´ 2011/10/17 ã³ã¡ã³ãã®ææã®ã¨ããæ·å± ãé«ãããã¼ãã«ãé«ãã«ä¿®æ£ãã¾ããã
id:neueccããã®ä½ã£ãReactivePropertyãæè¿ã¢ãã¤ã®ã§ãä»ããããä½ã£ã¦ãWindows Phone 7ã®ã¢ããªã±ã¼ã·ã§ã³ã§ãéä¸ããçµã¿è¾¼ãã§ä½¿ã£ã¦ã¿ã¾ãããã¾ã ã¢ããªã¯æªãªãªã¼ã¹ãªã®ã§ããã使ã£ã¦ã¿ãææ³ã¨ãããã©ãã©ã¨æ¸ãã¦ã¿ããã¨æãã¾ããã
ReactivePropertyã®åºæ¬çãªã¢ããã¼ã
ReactivePropertyã¯ãWPF/Silverlight/Windows Phone 7ã§ã®ã¢ããªã±ã¼ã·ã§ã³ã®éçºã§Reactive Extensionsã®ç¹å¾´ã§ããIObservable
- åèï¼ãã¼ã¿ã«ç¥è½ãæããã ã·ãªã¼ãº
- å è¨äº
- Rããã®Blog
- èªåã®Blog
ReactivePropertyã§ã¯ãReactiveProperty
ãã®ReactiveProperty
ä¾ã¯ãReactivePropertyã®ãã¼ã¸ãããã¦ã³ãã¼ããã¦ãµã³ãã«ãè¦ã¦ã¿ãã¨ããã¨æãã¾ãããã¨ãç´è¿ã®èªåã®Blogã®è¨äºã§æ¸ããã³ã¼ãã§ãããã©ãã ãå¼·åã«ããããªãã®ã¨çµ±åã§ããããªãã¨ãªããããã¨æãã¾ãã
// LINQ Padã§å®è¡ // åæåãã¦èªã¿è¾¼ã var load = new ReactiveCommand(); // ç¶ããèªã¿è¾¼ã var loadNext = new ReactiveCommand(); // çµæãããã¦ããã³ã¬ã¯ã·ã§ã³ var collection = default(ReactiveCollection<string>); collection = Observable .Merge( load.Do(_ => collection.Clear()), // loadã³ãã³ãã¯ã³ã¬ã¯ã·ã§ã³ãã¯ãªã¢ãã¦ç¶ãã®å¦çããã loadNext) // loadNextã¯ã³ã¬ã¯ã·ã§ã³ã¯ããããã«ç¶ãã®å¦çããã .Select(_ => Enumerable.Range(1, 5).ToObservable()) // ãã¼ã¿ã¨ã£ã¦ .Switch() .Select(i => string.Format("{0}æ³", i)) // å å·¥ã㦠.ToReactiveCollection(); // ã³ã¬ã¯ã·ã§ã³ã«ããã // åæç¶æ ã®åºå collection.Dump(); // æåã®èªã¿è¾¼ã¿ load.Execute(null); collection.Dump(); // ç¶ãã®ãã¼ã¿ã®èªã¿è¾¼ã¿ loadNext.Execute(null); collection.Dump(); // ãã¼ã¿ãåæåãã¦èªã¿è¾¼ã¿ load.Execute(null); collection.Dump();
å®è¡çµæ
# å®è¡çµæ #ã§å§ã¾ãè¡ã¯ç§ã追è¨ãã¦ã¾ã # åæç¶æ ã§ã¯0件 ReactiveCollection<String> (0 items) # loadã³ãã³ããå®è¡ããã¨5件èªã¿è¾¼ã¾ãã 5ReactiveCollection<String> (5 items) 1æ³ 2æ³ 3æ³ 4æ³ 5æ³ # loadNextã³ãã³ããå®è¡ããã¨ã¤ã¥ãã¦5件èªã¿è¾¼ã¾ãã 5ReactiveCollection<String> (10 items) 1æ³ 2æ³ 3æ³ 4æ³ 5æ³ 1æ³ 2æ³ 3æ³ 4æ³ 5æ³ # loadã³ãã³ããå®è¡ããã¨ä¸èº«ãã¯ãªã¢ããã¦ãã¼ã¿ãèªã¿è¾¼ã¾ãã 5ReactiveCollection<String> (5 items) 1æ³ 2æ³ 3æ³ 4æ³ 5æ³
ãã®æ¹æ³ã®ä¸æºç¹
ã¨ã¾ãé常ã«å¼·åã§ç´ æµãªReactivePropertyã§ããããã®ã¢ããã¼ããã¨ã£ãã¨ãã®å人çãªä¸æºç¹ã¨ãã¦ä»¥ä¸ã®ç¹ãããã¾ãã
- POCOã®ããããã£ãåæã«ãããã¼ã«ãã©ã³ã¿ã¤ã ãã³ã³ããã¼ã«ã®ãµãã¼ããåãããã¨ãã§ããªã
ä¸è¨ä¸ç¹ã«éãã¾ãããã¨ãã°ãDataGridãDataForm(Silverlight Toolkit)ã§ã¯ããããã£ã¨ãããã«ã¤ããå±æ§ã«ãã¨ã¥ãã¦èªåçã«ç»é¢ãæ§ç¯ãã¦ããã¾ãããããã£ãæ©è½ã¯ãå人çã«ã¯ä»å¾ã©ãã©ãå¼·åããã¦ãã£ã¦ã»ãããªã¨æã£ã¦ããã®ã§ãããReactivePropertyã®ãããªã¢ããã¼ããã¨ãå ´åã«ã¯è«¦ããå¿ è¦ãããã¾ããå人çã«ã¯DataGridãDataFormã®ã»ãã«ãåãç»é¢ãçæããã¨ãã«ä½¿ç¨ããæ¹æ³ã«å²ãè¾¼ãããããªãã¤ã³ããä½ã£ã¦ã»ãããªãã¨æãã¾ããï¼TypeProviderã¨ãã§é å¼µãã°ãããã¸ããªãã¨ããªãã®ããªï¼æªç¢ºèªï¼
æå¾ã«
ãã¦ããã®ReactivePropertyã§ããã¾ã ã¾ã betaã®æ®µéã§ããbetaã®æ®µéã§ã使ã£ã¦ã¦æ°æã¡ããæè¦ãä¸ãã¦ããããã¨ãç´ æµãªä»ä¸ããã«ãªã£ã¦ãã¾ããã³ã³ã»ãããç´ æ´ãããã¨æãã®ã§ãä»å¾æé·ãã¦ãã£ã¦ã»ãããªãã¨æãã¾ãï¼ï¼
ããããç¹å®MVVMã©ã¤ãã©ãªã«ä¾åããªãã®ã§ãã©ããªMVVMã©ã¤ãã©ãªã¨çµã¿åããã¦ãåºæ¬çã«ä½¿ããã¨ããã®ãç´ æµãªã¨ããã§ãããã ããMVVMã©ã¤ãã©ãªãPOCOã©ã¤ã¯ãªããããã£ãåæã«ãã¦ãæ©è½ãæä¾ãã¦ããå ´åã¯ä¸è¨ã®çç±ã¨åæ§ã«å©ç¨ã§ããªããã®ããããããããªãã®ã§ã使ç¨ããMVVMã©ã¤ãã©ãªã®æä¾ããæ©è½ã¨ReactivePropertyã®æ©è½ãè¦æ¯ã¹ã¦æé©ã ã¨æãæ©è½ããã§ã¤ã¹ããªãã¨ããã¾ããããããã¸ããMVVMã©ã¤ãã©ãªã«ãç²¾éãã¤ã¤Reactive Extensionsã®ãã¨ãç¥ã£ã¦ã¦ReactivePropertyã®æ¦è¦ãææ¡ãã¦ãªãã¨ãããªãä¸ã«å¿
è¦ã«å¿ãã¦MVVMã©ã¤ãã©ãªã¨ReactivePropertyãç¹ããããªæ©è½ãä½ããã¾ãªãã¨ãããªãã¨æãã®ã§å°ããã¼ãã«ãé«ãããããã¾ããããã¯ã¾ãã¨éçºå¹çã¯ä¸ããã¨æãã¾ãã
ã¨ãããã¨ã§ãMVVM + Reactive Extensionsã¨ãããã¼ãã«ã®é«ãï¼ä¸çã¸è¸ã¿åºããã人ã¯æ¯é使ã£ã¦ã¿ã¾ããããå ã¿ã«ãReactivePropertyã¯ã³ã³ã½ã¼ã«ã¢ããªã±ã¼ã·ã§ã³ã§ã使ããã®ã§ãããããã¦ãããç³»ã®ããã°ã©ã ã§ä½¿ã£ã¦ã¿ã¦ãä½è ããã£ã¨ãã©ãããããªãã¨ãã§ããããããã¾ãããï¼