attached-properties

Binding an attached property to an item in ItemsControl with custom panel problem

自闭症网瘾萝莉.ら 提交于 2019-12-05 17:18:51
I can't get the following XAML to work as I want. All bindings work because get no errors from the bindings. But I don't get the expected result from the binding on the RatioShape rectangle. The problem is that the attached property wpflib:RatioPanel.Ratio always returns its default value, not the databound value. So I'm thinking that the attached property on RatioShape is set in the wrong "context". How do bind to the attached property so that wpflib:RatioPanel gets the bound value? <wpflib:RatioContentPresenter2 RatioMaxValue="{Binding Path=RatioMaxValue}"> <ItemsControl Grid.Row="0" wpflib

What are the various uses of Attached Properties?

与世无争的帅哥 提交于 2019-12-05 12:49:34
I've seen some really varying uses of AttachedProperties so far in my adventures in WPF, and am wondering, what are some of the various uses? I've seen fairly mundane uses, such as those found in Grid and Canvas, as well as some really cool hacks allowing binding to collections without setters. What other applications have you found for AttachedProperties? (Code samples really helpful!) Take a look into attached behaviours. http://www.codeproject.com/KB/WPF/AttachedBehaviors.aspx //not sure on the quality of this link. First one I came to after googling. Attaching a behavior to an object

Creating an AttachedProperty to hold positions for scrollbar markers

五迷三道 提交于 2019-12-04 21:19:49
I have created slightly customized vertical scrollbar for my DataGrid. In it I have added an ItemsControl to hold positions of the selected items. Here is a mockup so far with hard-coded markers. Below is my customized vertical scrollbar template where the ItemsControl is placed with hard-coded marker values. <ControlTemplate x:Key="VertScrollBar" TargetType="{x:Type ScrollBar}"> <Grid> <Grid.RowDefinitions> <RowDefinition MaxHeight="18" /> <RowDefinition Height="0.00001*" /> <RowDefinition MaxHeight="18" /> </Grid.RowDefinitions> <Border Grid.RowSpan="3" CornerRadius="2" Background="#F0F0F0"

Displaying FontFamily in Combobox

≡放荡痞女 提交于 2019-12-04 06:28:05
My goal is to manipulate the text-styles of my application via DependencyProperties. I got a diagram in which the texts are to be manipulated in size, fontfamily, color, etc. So I'd like to use an interface similar to a rich text editor like Word. I'm using this code in my TextStyleVM http://shevaspace.blogspot.com/2006/12/i-have-some-fun-with-formattedtext_14.html So I have a FontFamilyProperty and a Getter and Setter for it: public static DependencyProperty FontFamilyProperty = DependencyProperty.Register( "FontFamily", typeof(FontFamily), typeof(OutlinedText), new FrameworkPropertyMetadata(

Template Binding for Custom Attached Property

断了今生、忘了曾经 提交于 2019-12-03 21:13:40
问题 I am trying to use an Image in Button Control which animates on Hover and Pressed state by showing different images. Accordingly, I have defined 3 attached properties for the Button Control as given below. public class ButtonExtensions : DependencyObject { public static DependencyProperty ImageSourceProperty = ... public static DependencyProperty ImageHoverSourceProperty = ... public static DependencyProperty ImagePressedSourceProperty = DependencyProperty.RegisterAttached("ImagePressedSource

Cell ControlTemplate binding to AttachedProperty binding to property of view model

心已入冬 提交于 2019-12-02 14:06:49
问题 Suppose I have a datagrid whose binded objects are of type ObjectVM: Public Class ObjectVM Implements INotifyPropertyChanged Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged Public Property NestedObject As New NestedVM End Class And NestedVM is defined as: Public Class NestedVM Implements INotifyPropertyChanged Public Event PropertyChanged(sender As Object, e As System

Getting the attached property “Canvas.Left”

浪尽此生 提交于 2019-12-02 09:39:41
问题 I have the following code: this.Object.GetType().GetProperty(this.PropertyName).GetValue(this.Object, null); PropertyName is a string, containing the name of the property I want to get. This works fine for "normal" properties, but I can't get the "Canvas.LeftProperty" or "Canvas.TopProperty". Can anyone help me out? Thanks, Chris 回答1: I think this is because Canvas.Left is attached property and to retrieve them try this: private DependencyProperty GetAttachedProperty(DependencyObject obj,

Getting the attached property “Canvas.Left”

萝らか妹 提交于 2019-12-02 07:11:14
I have the following code: this.Object.GetType().GetProperty(this.PropertyName).GetValue(this.Object, null); PropertyName is a string, containing the name of the property I want to get. This works fine for "normal" properties, but I can't get the "Canvas.LeftProperty" or "Canvas.TopProperty". Can anyone help me out? Thanks, Chris I think this is because Canvas.Left is attached property and to retrieve them try this: private DependencyProperty GetAttachedProperty(DependencyObject obj, string propertyName, Type ownerType) { foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(obj, new

Binding to attached property

和自甴很熟 提交于 2019-12-01 20:17:46
I'm trying to bind from Button's ContentTemplate to attached property. I read all the answers for question similar to "binding to attached property" but I had no luck resolving the problem. Please note that example presented here is a dumbed down version of my problem to avoid cluttering the problem with business code. So, I do have static class with attached property: using System.Windows; namespace AttachedPropertyTest { public static class Extender { public static readonly DependencyProperty AttachedTextProperty = DependencyProperty.RegisterAttached( "AttachedText", typeof(string), typeof

Template Binding for Custom Attached Property

冷暖自知 提交于 2019-11-30 22:46:20
I am trying to use an Image in Button Control which animates on Hover and Pressed state by showing different images. Accordingly, I have defined 3 attached properties for the Button Control as given below. public class ButtonExtensions : DependencyObject { public static DependencyProperty ImageSourceProperty = ... public static DependencyProperty ImageHoverSourceProperty = ... public static DependencyProperty ImagePressedSourceProperty = DependencyProperty.RegisterAttached("ImagePressedSource", typeof(string), typeof(ButtonExtensions)); public static string GetImagePressedSource(Button target)