Development Time Issue with Custom Behavior and Triggers in Silverlight

I implemented some custom actions and triggers and added them through XAML. They work fine at runtime, but do not allow the Cider design of the designer to load at design time and are likely to cause a problem in Blend as well, although I did not confirm this.

Here is a brief overview of what I implemented for one of the behaviors; hope someone can point out what i'm missing.

The behavior is as follows:

using System.Windows.Controls; using System.Windows.Data; using System.Windows.Interactivity; namespace MiX.Core.UI.Silverlight { public class UpdateOnTextChangedBehavior : Behavior<TextBox> { protected override void OnAttached() { base.OnAttached(); this.AssociatedObject.TextChanged += OnAssociatedObjectTextChanged; } void OnAssociatedObjectTextChanged(object sender, TextChangedEventArgs e) { BindingExpression binding = this.AssociatedObject.GetBindingExpression(TextBox.TextProperty); if (binding != null) { binding.UpdateSource(); } } protected override void OnDetaching() { base.OnDetaching(); this.AssociatedObject.TextChanged -= OnAssociatedObjectTextChanged; } } } 

The implementation in XAML looks like this:

 <TextBox x:Name="Username" Text="{Binding Username,Mode=TwoWay}" BorderThickness="1" Style="{StaticResource TextBoxStyleGeneral}" Foreground="#FF333333" FontSize="10" BorderBrush="{x:Null}" Grid.Column="1" d:LayoutOverrides="GridBox" Margin="2,0" Grid.ColumnSpan="2" Background="{x:Null}" VerticalAlignment="Center" Grid.Row="1"> <i:Interaction.Behaviors> <mixcore:UpdateOnTextChangedBehavior/> </i:Interaction.Behaviors> </TextBox> 

In the XAML editor, the <mixcore:UpdateOnPasswordChangedBehavior/> element is highlighted by squiggly and reports an error. A value of type "UpdateOnTextChangedBehavior" cannot be added to a collection or dictionary of type "BehaviorCollection" . When you try to view in the Design view, the designer does not load, specifying the Document contains errors that must be resolved before the designer can be loaded .

+4
source share
1 answer

In Silverlight, if the design cannot load with the changes we made to the code, then this is a mistake in silverlight.

Silverlight is not designed to handle various exceptions using code, for example, if you have any code with a return type and you don't check it there, and then it does not load the constructor. This case is mainly addressed using the Override of the IValueConverter {x: Static} ... method, etc.

There is nothing wrong with your code, unless it compiles and throws an exception. Do not worry about the designer.

Similarly, in one case, you can see: http://connect.microsoft.com/VisualStudio/feedback/details/361509/xaml-designer-cannot-handle-typename-with-nested-classes

+1
source

All Articles