开箱即用如果你开始使用Blend在网格上放一个按钮并在其上设置一些ChangeProeprtyActions ......将失败并显示错误消息。
<UserControl
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"
x:Class="SL4_Button_States.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="button" Content="Button" Height="39" Margin="68,42,299,0" VerticalAlignment="Top">
<i:Interaction.Triggers>
<i:EventTrigger>
<ei:ChangePropertyAction PropertyName="Content" Value="Button is now loaded!" TargetObject="{Binding ElementName=button}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction PropertyName="Content" Value="temporary"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Grid>
错误信息是:
Webpage error details
Message: Unhandled Error in Silverlight Application The type 'Object' was not found. [Line: 2 Position: 10] at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers, Boolean expandTemplatesDuringParse)
at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers)
at Microsoft.Expression.Interactivity.TypeConverterHelper.ExtendedStringConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at Microsoft.Expression.Interactivity.Core.ChangePropertyAction.Invoke(Object parameter)
at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
Line: 1
Char: 1
Code: 0
URI: http://localhost:62193/Silverlight.js
如果你在TextBlock上添加一个ChangePropertyAction ......工作正常:
<TextBlock Height="20" Margin="207,132,138,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<ei:ChangePropertyAction PropertyName="Text" Value="Mouse Left BUtton Down"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
如果您知道为什么会发生这种情况,请赐教......如果还有其他/更好的方式,除了州,请告诉我。
感谢。
答案 0 :(得分:3)
它失败了,因为Button上的Content属性不仅仅是一个字符串而是一个对象。尽管Blend会让你设置它,但我不确定它是否可行。要更改按钮的文本内容,您需要执行以下操作:
<Button x:Name="button" HorizontalAlignment="Left" Height="23" Margin="154,98,0,0" VerticalAlignment="Top" Width="113">
<Button.Content>
<TextBlock x:Name="btnText" Text="Orginal" />
</Button.Content>
<i:Interaction.Triggers>
<i:EventTrigger>
<ei:ChangePropertyAction PropertyName="Text" Value="Loaded" TargetName="btnText"/>
</i:EventTrigger>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction PropertyName="Text" Value="Clicked" TargetName="btnText"/>
</i:EventTrigger>
</i:Interaction.Triggers>
答案 1 :(得分:3)
如何通过Blend中的ChangePropertyAction更改Button的内容?
以下所有步骤均在Express Blend 4中。
XAML看起来像:
<Button Content="Button" HorizontalAlignment="Left" Margin="125,51,0,0" VerticalAlignment="Top" Width="75">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ei:ChangePropertyAction PropertyName="Content">
<ei:ChangePropertyAction.Value>
<TextBlock Text="HelloText"/>
</ei:ChangePropertyAction.Value>
</ei:ChangePropertyAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>