attached-properties

Bind Grid.Row / Grid.Column inside a DataTemplate

↘锁芯ラ 提交于 2019-12-17 16:09:27
问题 Hope this is not a dupe. I would like to be able to do the following in XAML: <DataTemplate DataType="{x:Type TestApp:ButtonVM}"> <Button Grid.Column="{Binding GridColumn}" Grid.Row="{Binding GridRow}" Content="{Binding Path=Info}" /> </DataTemplate> The Content binding works fine but Grid.Column and Grid.Row simply don't exist in the produced object. Not even when I set them to some value without binding (like in Grid.Column="1"). I've snooped the application and saw that inside my grid

Custom attached property of ResourceDictionary with implicit declaration syntax?

好久不见. 提交于 2019-12-14 04:27:20
问题 As you know a FrameworkElement has a property of type ResourceDictionary named Resources , in XAML we can declare it easily like this: <FrameworkElement.Resources> <SomeObject x:Key="someKey"/> <SomeOtherObject x:Key="someOtherKey"/> </FrameworkElement.Resources> It's some kind of implicit syntax, all the elements declared inside will be added to the ResourceDictionary . Now I would like to create an attached property having type of ResourceDictionary , of course a requirement of being

Calculate sum , average based on list of items in WPF

两盒软妹~` 提交于 2019-12-13 20:05:25
问题 In WPF, I want to display sum, average values based on the List of Items provided. For example, I have an Employee object with Salary Property, and I want to calculate total salary based on the employee list. Also, the employee object is data bound to a Items control where the Salary will be edited/new Employee may be added to the list. Can anyone provide me a solution to achieve this? 回答1: I would do this: In your code behind or ViewModel (if your using MVVM) create a new dependency property

style binding attached property didn't show up

半城伤御伤魂 提交于 2019-12-13 07:38:07
问题 I am trying to design a button: When the mouse hover on the button, the button content changes. So I am trying to use attached property to design it. Here is my attached class: class HotButtonAttached:DependencyObject { public static int GetNormalStr(DependencyObject obj) { return (int)obj.GetValue(NormalStrProperty); } public static void SetNormalStr(DependencyObject obj, int value) { obj.SetValue(NormalStrProperty, value); } // Using a DependencyProperty as the backing store for NormalStr.

Attached property binding proxy

风流意气都作罢 提交于 2019-12-12 02:55:36
问题 I have this binding in xaml: <Popup IsOpen="{Binding Path=(local:ListViewBehavior.IsColumnHeaderClicked), RelativeSource={RelativeSource FindAncestor, AncestorType=GridViewColumnHeader}}" ... Popup is located inside GridViewColumn.Header . ListViewBehavior.IsColumnHeaderClicked is a simple bool attached property: public static bool GetIsColumnHeaderClicked(DependencyObject obj) => (bool)obj.GetValue(IsColumnHeaderClickedProperty); public static void SetIsColumnHeaderClicked(DependencyObject

Are WPF Inherited Attached Dependency properties “expensive”?

落花浮王杯 提交于 2019-12-11 17:34:54
问题 I've got a working app that draws shapes and images on a zoomable canvas. I'm wondering about the effects of changing my current approach from using a global, transient settings object to using inherited attached properties. To explain: A few aspects of the drawing (e.g. line widths, font sizes, etc) are user-configurable but are also affected by zoom level. I quickly found that merely binding, say, the StrokeThickness of my shapes to a configured value caused problems. If the user zoomed the

Add Attach Property to Existing Control

一曲冷凌霜 提交于 2019-12-11 14:09:21
问题 I want to add a Property such as 'Description' to Button control, that i use it in Tooltip. how can i add a property to a control? 回答1: Attached properties are not added to any specific control. Attached properties are defined in static class, and can be used with any UI control. Refer to this link to for walkthrough to Add custom attached property. You can Bind ToolTipService to display tooltip. You need to bind it to Description attached property. If you want to put property in only one

Attached property: Check binding

故事扮演 提交于 2019-12-11 13:39:39
问题 Short question Is there a quick way of knowing what a particular attached property is bound to, at runtime? Detail I'm debugging a UserControl (that inherits ItemsControl ) which binds Canvas.Left and Canvas.Top of its items to two properties of the ViewModel objects, through a style. At runtime, I place a breakpoint at a certain location and want to inspect the binding of Canvas.Left attached property. Note that I do not want to see the current value of the attached property for an item. I

Attached or dependecy Property for ValidationRule WPF

风格不统一 提交于 2019-12-11 12:14:08
问题 I want to bind the attached property or dependency property in xaml for the ValidationRule in xaml and then based on the value of the attached property or dependency property I want to make sum decision in the Validation rule. I can't find any solution how can I Pass bindable value to the Validation Rule. 回答1: I supply you a sample code to help you. I have defined a ValidationRule to validate a texbox user input. The type of validation is performed according value of one enum parameter. Type

Create attached property dynamically

会有一股神秘感。 提交于 2019-12-11 08:05:14
问题 Trying to refactor one tedious solution, I've come to brilliant idea of creating attached properties dynamically, basically: void SomeMethod() { ... var dp = DependencyProperty.RegisterAttached("SomeUniqueOrGeneratedName333", typeof(object), typeof(CurrentClass)); ... } It is not the recommended way. I am using such properties (big surprise, like if someone uses attached properties for something else) as storage for some related to object data (namely bindings). Those are retrieved later in