Out of the box if you crank up Blend put a button on a grid and set a couple of ChangeProeprtyActions on it ... will fail with an error message.
<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>
The error message is this:
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
If you add a ChangePropertyAction on a TextBlock ... works fine:
<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>
If you have any idea why this happens please enlighten me ... if there is another/better way of doing this, other than states please let me know.
Thanks.
Answer: 1
It is failing because the Content property on a Button is not just a string but an object. Even though Blend will let you set it I'm not sure that it is possible. To change the text content of the button you would need to do something like this:
<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>
Answer by Bryant for Silverlight ChangePropertyAction on Button control not workingAnswer: 2
Button x:Name="button" Content="Button" Height="39" Margin="68,42,299,0" Click="button_Click" MouseRightButtonDown="button_MouseRightButtonDown" VerticalAlignment="Top"
private void button_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { ((Button)sender).Content = "Right Click"; } private void button_Click(object sender, RoutedEventArgs e) { ((Button)sender).Content = "Button Click"; }
Answer by mani kandan for Silverlight ChangePropertyAction on Button control not workingAnswer: 3
How to change Button's Content via ChangePropertyAction in Blend?
All following steps are in Express Blend 4.
- Add a Button in ArtBoard. Drag "ChangePropertyAction" from Assets to the button.
- In Data panel, create a new ContentControl data source (click "Create Object Data Source", search "ContentControl" and click OK. The datasource will be named as ContentControlDataSource).
- In Object and Timeline, focus the ChangePropertyAction of button. In Property->Common Properties->PropertyName, select "Content", and create a data binding to the ContentControlDataSource with Value. (while setting Value of Content, click the small rectangle at the end of value. Choose 'Data Binding...", in the "Create Data Binding" dialog, select ContentControlDataSource in Data Field)
- In Object and Timeline panel, unfocus then focus again the ChangePropertyAction of button. In Property->Common Properties->Value, you can see a yellow rectangle around the text like "(ContentControl) New". Click the small yellow rectangle at the end and select "Reset". After the yellow rectangle disappear, click the New button after Value property. When the "Select Object" dialog pops up, search "TextBlock" and add it. Then set the TextBlock's Text as you want. Build and test it now. Click the button and you can see the text is changed to what you set.
The XAML looks like:
<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>
Answer by Tealc Wu for Silverlight ChangePropertyAction on Button control not working
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog