Expression Blend 3ãããããåãå ¥ããããBehaviorã¨ãã便å©ãªå¥´ãããã¾ããããã使ãã¨ã³ã³ããã¼ã«ãªããã®ã¤ãã³ãã«å¿çãã¦ä½ããããã¨ããããã¨ããã¶ã¤ããããããã¿ã§å®è¡ãããã¨ãã§ãã¾ãã
ãã®Behaviorã®æ©æµããã«ã«åãããã¨æãã¨Expression Blendãå¿
è¦ã«ãªãã¾ãããBehaviorã使ã£ããä½ã£ããããã¶ãã«ã¯Expression Blendãç¡ãã¦ãOKã§ããã¨ãããã¨ã§æ©é使ã£ã¦ã¿ã¾ãã
Behaviorã使ãã«ã¯ã以ä¸ã®ãµã¤ãããExpression Blendã®SDKããã¦ã³ãã¼ããã¦ã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ããï¼ç¡æï¼
- .NET FW4:http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=75e13d71-7c53-4382-9592-6c07c6a00207
- SL4:http://www.microsoft.com/downloads/details.aspx?familyid=D197F51A-DE07-4EDF-9CBA-1F1B4A22110D&displaylang=en
(èªåã¯Blendãå ¥ã£ã¦ãã®ã§ä¸ç¢ºããªæ å ±ã§ããï¼ãã¶ãã¤ã³ã¹ãã¼ã«ããã¨C:\Program Files\Microsoft SDKs\Expression\Blend\.NETFramework(or Silverlight)\v4.0\Librariesã¨ãããã©ã«ããåºæ¥ã¾ãããã®ä¸ã«System.Windows.Interactivity.dllã¨Microsoft.Expression.Interactions.dllãããã®ã§Visual Studioããåç §ã«è¿½å ãã¦ä½¿ãã¾ãã
System.Windows.Interactivity.dllã¯ãBehaviorã®åºæ¬ã¯ã©ã¹ãªã©ãå ¥ã£ã¦ãã¦Microsoft.Expression.Interactions.dllã«ä¾¿å©ãªBehaviorãå ¥ã£ã¦ãã¤ã¡ã¼ã¸ã§ãã
ã¨ãããã¨ã§ãæ©é使ã£ã¦ã¿ã¾ããVisualStudioBehaviorã¨ããååã§WPFã¢ããªã±ã¼ã·ã§ã³ãä½æãã¦ãå
ã»ã©ã®ã¢ã»ã³ããªãï¼ã¤åç
§ã«è¿½å ãã¾ãã
ã¨ããããããã®éBlendã§ä½¿ã£ã¦ã¦ä¾¿å©ã ã¨æããCallMethodActionã使ã£ã¦ã¿ããã¨æãã¾ããã¾ãã以ä¸ã®xmlnsãï¼ã¤å®ç¾©ãã¾ãã
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
CallMethodActionããå¼ã¶ããã®ã¡ã½ãããMainWindow.xaml.csã«ããã£ã¨ä½æãã¾ããå¼ã°ãããã¨ããããã°ããã®ã§MessageBoxãåºãã ãã®ã·ã³ãã«ãªã¡ã½ããã«ãã¾ããã
namespace VisualStudioBehavior { using System.Windows; /// <summary> /// MainWindow.xaml ã®ç¸äºä½ç¨ãã¸ã㯠/// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } // ã¡ãã»ã¼ã¸ããã¯ã¹ãåºã public void Alert() { MessageBox.Show("Hello world"); } } }
XAMLã«æ»ã£ã¦Behaviorã使ã£ã¦ã¿ã¾ããã¨ããããããActionã¨ããååã®ããã¤ãã¢ã¯ãTriggerã¨å¼ã°ããActionãèµ·åãããã£ããã¨ã»ããã§ä½¿ãã¾ããä¸çªãã使ãã®ãã¤ãã³ãããã£ããã«Actionãå®è¡ããEventTriggerã ã¨æãã¾ããã¨ãããããç»é¢ã«ãã¿ã³ãç½®ãã¦ãã¿ã³ã®ã¯ãªãã¯ã¤ãã³ãã§Alertã¡ã½ãããå®è¡ããããã«XAMLãç·¨éãã¾ãã
<Window x:Class="VisualStudioBehavior.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" Name="Window" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="Hello world"> <i:Interaction.Triggers> <!-- Clickã¤ãã³ããããªã¬ã¼ã«ãã --> <i:EventTrigger EventName="Click"> <!-- Windowã®Alertã¡ã½ãããå¼ã¶ --> <ei:CallMethodAction TargetObject="{Binding ElementName=Window}" MethodName="Alert" /> </i:EventTrigger> </i:Interaction.Triggers> </Button> </Grid> </Window>
ãããå®è¡ãã¦ãã¿ã³ãã¯ãªãã¯ããã¨Hello worldã¨è¡¨ç¤ºãããMessageBoxã表示ããã¾ãã
ã¨ãããã¨ã§ãBlendãç¡ãã¦ãã¡ããã¨Behavior使ãã¾ã£ãã¨ãããã¨ã§ããã*1
*1:ãã ãçåã¨ãã¦ã¯ãããã ãXAMLãææ¸ãããã®ã¨ã¤ãã³ããã³ãã©ã§ã¡ã½ãããåç´ã«å¼ã³åºãã³ã¼ããæ¸ãã®ã©ã£ã¡ãããã®ãã¯å¾®å¦ãªã¨ããï¼ï¼