dependency-properties

Why Would a Dependency-Property Implementation Crash My Application When I Provide a Default Value?

爱⌒轻易说出口 提交于 2019-12-18 03:39:33
问题 Why would a dependency-property implementation crash my application when I provide a default value? This segment of code is in the class declaration for my UserControl object. Everything works fine - it compiles and runs perfectly. public static System.Windows.DependencyProperty DepProp = System.Windows.DependencyProperty.Register( "Rect", typeof(System.Windows.Shapes.Rectangle), typeof(FooControl)); public System.Windows.Shapes.Rectangle Rect { get { return ((System.Windows.Shapes.Rectangle)

Why does my data binding see the real value instead of the coerced value?

人走茶凉 提交于 2019-12-18 03:16:33
问题 I'm writing a real NumericUpDown/Spinner control as an exercise to learn custom control authoring. I've got most of the behavior that I'm looking for, including appropriate coercion. One of my tests has revealed a flaw, however. My control has 3 dependency properties: Value , MaximumValue , and MinimumValue . I use coercion to ensure that Value remains between the min and max, inclusive. E.g.: // In NumericUpDown.cs public static readonly DependencyProperty ValueProperty = DependencyProperty

WPF dependency property precedence & reference type Default Values

爷,独闯天下 提交于 2019-12-17 21:15:13
问题 If I create a custom control like this: public class MyControl : ContentControl { public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register( "Items", typeof(ObservableCollection<object>), typeof(MyControl), new PropertyMetadata(null)); public MyControl() { // Setup a default value to empty collection // so users of MyControl can call MyControl.Items.Add() Items = new ObservableCollection<object>(); } public ObservableCollection<object> Items { get { return

ObservableCollection dependency property does not update when item in collection is deleted

☆樱花仙子☆ 提交于 2019-12-17 18:26:18
问题 I have a attached property of type ObservableCollection on a control. If I add or remove items from the collection, the ui does not update. However if I replace the collection within with a new one the ViewModel the ui does update. Can someone give me an example of what I need to do within the Dependency object so that it can handle changes within the collection? Part of the dependency object is listed below: public class RadCalendarBehavior : DependencyObject { private static void

WPF: What distinguishes a Dependency Property from a regular CLR Property?

眉间皱痕 提交于 2019-12-17 17:59:19
问题 In WPF, what, really, does it mean to be a "dependency property"? I read Microsoft's Dependency Properties Overview, but it's not really sinking in for me. In part that article says: Styles and templates are two of the chief motivating scenarios for using dependency properties. Styles are particularly useful for setting properties that define application user interface (UI). Styles are typically defined as resources in XAML. Styles interact with the property system because they typically

Property Changed in DependencyProperty

半世苍凉 提交于 2019-12-17 17:11:35
问题 In a previous post I asked how to register a property as DependencyProperty. I got an answer and it works fine. But now I want to add some Items to this DependencyProperty on a Click. This doesn't work. My code to register the DependencyProperty is: public static readonly DependencyProperty ChartEntriesProperty = DependencyProperty.Register( "ChartEntries", typeof(ObservableCollection<ChartEntry>), typeof(ChartView), new FrameworkPropertyMetadata(OnChartEntriesChanged)); private static void

Why dependency properties?

半城伤御伤魂 提交于 2019-12-17 15:27:21
问题 Why did Microsoft go the route of making dependency properties and dependency objects instead of using reflection and maybe attributes? 回答1: This helped me understand the reasoning: The main difference is, that the value of a normal .NET property is read directly from a private member in your class , whereas the value of a DependencyProperty is resolved dynamically when calling the GetValue() method that is inherited from DependencyObject . When you set a value of a dependency property it is

Hiding inherited members

戏子无情 提交于 2019-12-17 11:18:07
问题 I'm looking for some way to effectively hide inherited members. I have a library of classes which inherit from common base classes. Some of the more recent descendant classes inherit dependency properties which have become vestigial and can be a little confusing when using IntelliSense or using the classes in a visual designer. These classes are all controls that are written to be compiled for either WPF or Silverlight 2.0. I know about ICustomTypeDescriptor and ICustomPropertyProvider , but

WPF: XAML property declarations not being set via Setters?

醉酒当歌 提交于 2019-12-17 06:16:08
问题 I have a WPF application where I'm using dependency properties in codebehind which I want to set via XAML declarations. e.g. <l:SelectControl StateType="A" Text="Hello"/> So in this example I have a UserControl called SelectControl , which has a property called StateType which manipulate some other properties in it's setter. To help illustrate the problem, I've put another property called Text in the example, read on and I'll explain further. Codebehind excerpt... public static readonly

DependencyProperty getter/setter not being called

China☆狼群 提交于 2019-12-17 02:33:12
问题 I am trying to create a Custom control derived from a standard Grid. I added a ObservableCollection as a DependencyProperty of the Custom control. However, the get/set of it is never reached. Can I have some guidelines in creating a DependencyProperty that works correctly with and ObservableCollection? public class MyGrid : Grid { public ObservableCollection<string> Items { get { return (ObservableCollection<string>)GetValue(ItemsProperty); } set { SetValue(ItemsProperty, value); } } public