attachedbehaviors

unit test an attached behavior wpf

我们两清 提交于 2019-12-04 05:02:23
I am still grokking attached behaviors in general, and am at a loss to see how to write a unit test for one. I pasted some code below from Sacha Barber's Cinch framework that allows a window to be closed via attached behavior. Can somewone show me an example unit test for it? Thanks! Berryl #region Close /// <summary>Dependency property which holds the ICommand for the Close event</summary> public static readonly DependencyProperty CloseProperty = DependencyProperty.RegisterAttached("Close", typeof(ICommand), typeof(Lifetime), new UIPropertyMetadata(null, OnCloseEventInfoChanged)); ///

Attach behaviour to all TextBoxes in Silverlight

和自甴很熟 提交于 2019-12-03 14:34:39
Is it possible to attach behavior to all TextBoxes in Silverlight application? I need to add simple functionality to all text boxes. (select all text on focus event) void Target_GotFocus(object sender, System.Windows.RoutedEventArgs e) { Target.SelectAll(); } You can override the default style for TextBoxes in your app. Then in this style, you can use some approach to apply a behavior with a setter (generally using attached properties). It would something like this: <Application.Resources> <Style TargetType="TextBox"> <Setter Property="local:TextBoxEx.SelectAllOnFocus" Value="True"/> </Style>

Using MouseDragElementBehavior with an ItemsControl and Canvas

假如想象 提交于 2019-12-02 02:21:17
I am currently having a problem using the MouseDragElementsBehavior from the Blend SDK when using a ItemsControl and a Custom Canvas. My custom canvas simply adds or removes the MouseDragElement from its children depending on a DependencyProperty. This worked just fine when I was manually adding Items to the Canvas' children but appears to have broken when moving to an ItemsControl. I am currently using the following ItemsControl code: <ItemsControl ItemsSource="{Binding Path=CanvasItems}"> <ItemsControl.DataContext> <ViewModels:ViewModel/> </ItemsControl.DataContext> <ItemsControl.ItemsPanel>

How to animate an Image in a button to shake every 30 seconds in WPF?

Deadly 提交于 2019-12-01 14:45:49
I not good when it comes to dealing with anything with styles and animations. I was hoping to be able to get some help on making an Image that is the only content of a Button shake every 30 seconds when ever the buttons Visibility is set to Visibility.Visible. It is to get the users attention to encourage them to click the button. I would prefer to do this as an attached behavior on Image, or if possible even UIControl, to make it easily reusable instead of messing with the style, as I am already using a style from my control vendor, and I don't want to edit it. Here is the solution I used

How to animate an Image in a button to shake every 30 seconds in WPF?

主宰稳场 提交于 2019-12-01 12:36:22
问题 I not good when it comes to dealing with anything with styles and animations. I was hoping to be able to get some help on making an Image that is the only content of a Button shake every 30 seconds when ever the buttons Visibility is set to Visibility.Visible. It is to get the users attention to encourage them to click the button. I would prefer to do this as an attached behavior on Image, or if possible even UIControl, to make it easily reusable instead of messing with the style, as I am

How can I attach two attached behaviors to one XAML element?

萝らか妹 提交于 2019-12-01 01:59:52
I've implemented the attached command behavior pattern found here and it works well to allow e.g. a Border to have a left- or right-click event that fires in the ViewModel: XAML: <Border Background="Yellow" Width="350" Margin="0,0,10,0" Height="35" CornerRadius="2" c:CommandBehavior.Event="MouseLeftButtonDown" c:CommandBehavior.Command="{Binding PressedLeftButton}" c:CommandBehavior.CommandParameter="MainBorder123"> <TextBlock Text="this is the click area"/> </Border> Code Behind: public ICommand PressedLeftButton { get; private set; } public MainViewModel() { Output = "original value";

Blend Behaviours - can you bind to their properties?

淺唱寂寞╮ 提交于 2019-11-30 13:53:41
I am currently migrating a number of attached behaviours I have created to Blend Behaviours so that they support drag and drop within Expression Blend. I have noticed that authors of Blend behaviours tend to define the behaviour properties as dependency properties. I have created a behaviour, TiltBehaviour , which exposes a public dependency property, TiltFactor , of type double. Within Expression Blend I can set the value of this property, however, the option to add a "Data Binding ..." is grayed out: I have also noticed that Behaviors extend DependencyObject , therefore they do not have a

SL4/MVVM: Handle MouseDragElementBehavior.Dragging event with void Foo() in VM

安稳与你 提交于 2019-11-30 09:24:01
问题 I am trying to handle the MouseDragElementBehavior.Dragging event on a control I have. See here for background on why I want to do this. I am having trouble wiring up this event. From the XAML you can see I have added a behavior to the user control. Then I attempted to add a handler to the Dragging event on the behavior via the CallMethodAction EventTrigger. <i:Interaction.Behaviors> <ei:MouseDragElementBehavior ConstrainToParentBounds="True"> <i:Interaction.Triggers> <i:EventTrigger

When should I use FrameworkPropertyMetadata or UIPropertyMetadata over plain PropertyMetadata?

烂漫一生 提交于 2019-11-29 20:01:19
When looking at sample attached properties and behaviors, I've seen a mishmash of uses of FrameworkPropertyMetadata , UIPropertyMetadata and PropertyMetadata . Since they all form an inheritance hierarchy, how do I choose which one to use? gp. These classes are to report some behavior aspects of a dependency property. Check the different classes for the options they provide. For example, if you just want to back a property by dp and provide a default value, use PropertyMetadata , if you want to specify animation behavior, use UIPropertyMetadata , but if some property affects wpf framework

Blend Behaviours - can you bind to their properties?

£可爱£侵袭症+ 提交于 2019-11-29 19:18:48
问题 I am currently migrating a number of attached behaviours I have created to Blend Behaviours so that they support drag and drop within Expression Blend. I have noticed that authors of Blend behaviours tend to define the behaviour properties as dependency properties. I have created a behaviour, TiltBehaviour , which exposes a public dependency property, TiltFactor , of type double. Within Expression Blend I can set the value of this property, however, the option to add a "Data Binding ..." is