views:

74

answers:

0

I have implemented a few custom behaviors and triggers and added them via XAML. They work fine at run time but prevent the Cider designer view from loading at design time, and presumably will cause a problem in Blend too, though I haven't confirmed that.

Here is an overview of what I've implemented for one of the behaviors; hopefully someone can point out what I'm missing.

The behavior looks like this;

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;
        }
    }
}

An 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 with a squiggly and reports the error A value of type 'UpdateOnTextChangedBehavior' cannot be added to a collection or dictionary of type 'BehaviorCollection'. When attempting to view in the Design view the designer fails to load, stating The document contains errors that must be fixed before the designer can be loaded.