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 .
source share