attached-properties

Attached property of type list

核能气质少年 提交于 2019-11-30 01:51:17
I want to create an attached property that can be used with this syntax: <Button> <Image .../> <ui:ToolbarItem.DisplayFilter> <TabItem .../> <TabItem .../> <TabItem .../> </ui:ToolbarItem.DisplayFilter> </Button> This is my attempt at doing so: public class ToolbarItem { /// <summary> /// Identifies the DisplayFilter attached property. /// </summary> public static readonly DependencyProperty DisplayFilterProperty = DependencyProperty.RegisterAttached( "DisplayFilter", typeof( IList ), typeof( ToolbarItem ) ); public static IList GetDisplayFilter( Control item ) { return (IList)item.GetValue(

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

Set custom attached property in style setter

时光毁灭记忆、已成空白 提交于 2019-11-29 16:39:01
Im trying to set attached property inside a style, i want to use them to attach behaviour. However I cant get it to work. Heres code: Attached property public class TestBehaviour { public static bool GetTest(Grid grid) { return (bool)grid.GetValue(TestProperty); } public static void SetTest(Grid grid, bool value) { grid.SetValue(TestProperty, value); } public static readonly DependencyProperty TestProperty = DependencyProperty.RegisterAttached("Test", typeof(bool), typeof(Grid)); } Xaml <Window x:Class="AttachedPropertyTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml

Attached Property Changed Event? [duplicate]

本小妞迷上赌 提交于 2019-11-29 04:29:32
This question already has an answer here: How do I handle Canvas.Top change event in WPF? 1 answer ist there a way to get a change notification if an attached property changed? A simple example is a Canvas with a Rectangle in it. The position of the Rectange is set by using the DepenendyProperties Canvas.Top and Canvas.Left . I'm using an Adorner to move the Rectangle around by changing the Canvas.Top and Canvas.Left . <Canvas Width="500" Height="500" > <Rectangle Width="40" Height="40" Canvas.Left="10" Canvas.Top="20" /> </Canvas> The next step is to create an Arrow between two Rectangles .

How do I handle Canvas.Top change event in WPF?

浪尽此生 提交于 2019-11-29 03:57:30
I have an element positioned on Canvas using attached properties Canvas.Top and Canvas.Left . Then using animations the element is moved to different set of coordinates, like this: DoubleAnimation left = new DoubleAnimation( oldLeft, newLeft ); DoubleAnimation top = new DoubleAnimation( oldTop, newTop ); element.BeginAnimation( Canvas.LeftProperty, left ); element.BeginAnimation( Canvas.TopProperty, top ); Is there a way to receive events whenever Canvas.Top or Canvas.Left is changed? Preferably without relation to animation. One can catch attached property changed event using

Attached property of type list

自闭症网瘾萝莉.ら 提交于 2019-11-28 22:41:25
问题 I want to create an attached property that can be used with this syntax: <Button> <Image .../> <ui:ToolbarItem.DisplayFilter> <TabItem .../> <TabItem .../> <TabItem .../> </ui:ToolbarItem.DisplayFilter> </Button> This is my attempt at doing so: public class ToolbarItem { /// <summary> /// Identifies the DisplayFilter attached property. /// </summary> public static readonly DependencyProperty DisplayFilterProperty = DependencyProperty.RegisterAttached( "DisplayFilter", typeof( IList ), typeof(

When should I use FrameworkPropertyMetadata or UIPropertyMetadata over plain PropertyMetadata?

我们两清 提交于 2019-11-28 15:15:34
问题 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? 回答1: 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

Set custom attached property in style setter

Deadly 提交于 2019-11-28 11:56:18
问题 Im trying to set attached property inside a style, i want to use them to attach behaviour. However I cant get it to work. Heres code: Attached property public class TestBehaviour { public static bool GetTest(Grid grid) { return (bool)grid.GetValue(TestProperty); } public static void SetTest(Grid grid, bool value) { grid.SetValue(TestProperty, value); } public static readonly DependencyProperty TestProperty = DependencyProperty.RegisterAttached("Test", typeof(bool), typeof(Grid)); } Xaml

How to I access an attached property in code behind?

时光毁灭记忆、已成空白 提交于 2019-11-28 04:48:10
I have a rectangle in my XAML and want to change its Canvas.Left property in code behind: <UserControl x:Class="Second90.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300" KeyDown="txt_KeyDown"> <Canvas> <Rectangle Name="theObject" Canvas.Top="20" Canvas.Left="20" Width="10" Height="10" Fill="Gray"/> </Canvas> </UserControl> But this doesn't work: private void txt_KeyDown(object sender, KeyEventArgs e) { theObject.Canvas.Left = 50; } Does anyone know what the syntax is to do this? AnthonyWJones

using attached events with caliburn micro Message.Attach

故事扮演 提交于 2019-11-27 20:42:34
I'm trying to use caliburn micro message to trigger an attached event that I created: public static class DataChanging { public delegate void DataChangingEventHandler(object sender, DataChangingEventArgs e); public static readonly RoutedEvent ChangingEvent = EventManager.RegisterRoutedEvent("Changing", RoutingStrategy.Bubble, typeof(DataChangingEventHandler), typeof(DataChanging)); public static void AddChangingHandler(DependencyObject o, DataChangingEventHandler handler) { ((UIElement)o).AddHandler(DataChanging.ChangingEvent, handler); } public static void RemoveChangingHandler