.net/XAML/C#: XAML ã®ããããã£ã¼ã¯ Visibility åã ãã© Boolean ã® DataContext ã«æç¸ãããå ´åã®æé©è§£ãããã㯠BooleanToVisibilityConverter ã«ã¤ãã¦
ãBoolean
ãªããããã£ã¼ Hoge
ã DataContext
ã«æç¸ããã Window
ã®ã«ããä½ãã®ã³ã³ããã¼ã«ï¼ä¸ã®ä¾ã§ã¯ Button
ï¼ã® Visibility
ããããã£ã¼ã XAML
ã ãã§ç°¡åã« Window
ã® DataContext
ã® Hoge
ã«æç¸ãããï¼ãã¨æã£ããã ã
<Window ... ç¥ ...> ... ç¥ ... <Button Visibility="{Binding ð Hoge ? Visible : Hidden ããããã ãã©ï¼ï¼ð}"/> ... ç¥ ... </Window>
ããããããXAML ãªã¼ããã¯ã«ã©ã³â¦ ï¼ãã©ä½ãè¯ãæ¹æ³ã¯ãããããã⦠ï¾(ï¾âï¾ï¾) ï¼ã
ã¨ãæã£ãã®ã ãã© XAML
é¢é£ã®ç¥èãä¹ããã®ã§ msdn ã stackoverflow ãçºããã«ãçãã«è¿ãããªãã¼ã¯ã¼ããããããªãã®ã§ãããã XAML é¢é£ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãã Binding ãã Command ãããå°å³ã«èªãã§â¦ããã®ã ãã©ãã¤ã³ã¿ã¼ãã§ã¼ã¹ã®å®ç¾©ãã dynamic
ãªæé»åªæã®ææ¡ããé¢åãããã¼ãªã³ããå¿
è¦ãªãããã°ã©ãã¼ã»ã¹ããªããªãã£ã¼çã« ctor
ï¼ç¶æ
å¤æ´ãå¿
è¦ã«ãªãã¿ã¤ãã³ã°ã¤ãã³ãã« Visibility
ããããã£ã¼ãæ´æ°ãã .cs å®è£
ãæ¸ããæ¹ãã¯ããã¦æ¥½ãªãã§ããâ¦ã¨ãæãå§ããã®ãã
ããã§ããã§ãã諦ãã¦ããããå®è£ ã«ããããã¨æããªãããâ¦
ãªã©ã¨ä»åæ¬é¡ãããããã¨ã£ã¡ãããããã¾ãã«æ±ãã¦ããããçãªæé©è§£ãæãã¦ããã¾ããð
ã¤ã¾ãâ¦
<Window ... ç¥ ...> <Window.Resources> <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> </Window.Resources> ... ç¥ ... <Button Visibility="{Binding Hoge,Converter={StaticResource BooleanToVisibilityConverter}}"/> ... ç¥ ... </Window>
ããã ãã§è¯ãã£ããã ãð ã«ã³ã¿ã³ãæ¸ãéãå¿ è¦æä½éã§æ¸ãã§ã¾ãã£ã¦æããã¨ã£ã¦ãæé©è§£â¥
ãã¾ã: ãã®å¾ã®ä¼è©±ã®ç¶ã
ãããã¨ããããã¾ããð