dependency-properties

When to use a WPF Dependency Property versus INotifyPropertyChanged

倖福魔咒の 提交于 2019-12-28 11:44:11
问题 Do folks have any guidance on when a simple .NET property that fires INotifyPropertyChanged.PropertyChanged is sufficient in a view model? Then when do you want to move up to a full blown dependency property? Or are the DPs intended primarily for views? 回答1: There are a few approaches: 1. The dependency property While you using the dependency property it makes the most sense in elements-classes that have a visual appearance ( UIElement s). Pros: WPF do the logic stuff for you Some mechanism

A 'Binding' can only be set on a DependencyProperty of a DependencyObject

做~自己de王妃 提交于 2019-12-28 05:36:18
问题 From a custom control based on TextBox , I created a property named Items , in this way: public class NewTextBox : TextBox { public ItemCollection Items { get; set; } } When using the custom control in XAML, I cannot bind the property because it raises exception "A 'Binding' can only be set on a DependencyProperty of a DependencyObject.". How do I solve this exception? 回答1: As a side note, it is also worth noting that you will get these binding errors if you copy and paste between objects and

A 'Binding' can only be set on a DependencyProperty of a DependencyObject

跟風遠走 提交于 2019-12-28 05:36:16
问题 From a custom control based on TextBox , I created a property named Items , in this way: public class NewTextBox : TextBox { public ItemCollection Items { get; set; } } When using the custom control in XAML, I cannot bind the property because it raises exception "A 'Binding' can only be set on a DependencyProperty of a DependencyObject.". How do I solve this exception? 回答1: As a side note, it is also worth noting that you will get these binding errors if you copy and paste between objects and

What's the difference between a dependency property and an attached property in WPF?

妖精的绣舞 提交于 2019-12-27 12:14:45
问题 What's the difference between a (custom) dependency property and an attached property in WPF? What are the uses for each? How do the implementations typically differ? 回答1: Attached properties are a type of dependency property. The difference is in how they're used. With an attached property, the property is defined on a class that isn't the same class for which it's being used. This is usually used for layout. Good examples are Panel.ZIndex or Grid.Row - you apply this to a control (ie:

How to setup UserControl

血红的双手。 提交于 2019-12-25 19:04:15
问题 In an application I have the (simplified) task: The application manages information about persons. The persons are stored somewhere (doesn't matter). The user can add and remove persons to the list. The list of persons (that is used quite often in the program) looks like this: <UserControl> ... <StackPanel> <ListBox ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson}" SelectionMode="Single"/> <StackPanel Orientation="Horizontal"> <Button Content="Add Person" Command="

error in creating an instance of class in xaml and setting its properties

自作多情 提交于 2019-12-25 16:46:40
问题 i need to create an instance of a class with two property that would be used as converter parameter of a binding. the class is as below: public class UnitQuantityBindClass:DependencyObject { public static readonly DependencyProperty QuantityProperty = DependencyProperty.Register( "Quantity", typeof(EQuantities), typeof(UnitQuantityBindClass)); public EQuantities Quantity { get { return (EQuantities) GetValue(QuantityProperty); } set { SetValue(QuantityProperty, value); } } public static

trainings DependencyObject - custom command

烂漫一生 提交于 2019-12-25 09:20:03
问题 I try to create Command which inherit from DependencyObject and ICommand. I have the following code: public class CustomCommand : DependencyObject, ICommand { public static readonly DependencyProperty CommandProperty; public static readonly DependencyProperty AfterCommandProperty; static CustomCommand() { var ownerType = typeof(CustomCommand); CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(Action), ownerType, new PropertyMetadata(null)); AfterCommandProperty =

WPF dependency property MVVM

泪湿孤枕 提交于 2019-12-25 05:09:34
问题 I am in the process of creating a user control, this control will do some work and then populate three dependency properties, which will then used by parent elements of the control through binding. My question is what are the best practices on where to keep the dependency properties using MVVM? Should I use a framework for MVVM? Thanks 回答1: Idiomatic dependency properties have nothing to do with 'view state' as represented by the ViewModel and there is no reason to add them to the ViewModel.

Access `DependencyProperty` via XAML and evaluate it?

▼魔方 西西 提交于 2019-12-25 04:18:10
问题 I just created a DependencyProperty for my custom button. The property is called IsChecked . If IsChecked == true my button shall change its background color to something else and keep this color until IsChecked == false . Here is my DependencyProperty : public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(MainMenuButton), new PropertyMetadata(false)); public bool IsChecked { get { return (bool)GetValue(IsCheckedProperty);

why doesn't a polyline redraw when I change its Points collection to reference a different collection?

自作多情 提交于 2019-12-25 03:16:32
问题 I'm still fairly new to silverlight, so hopefully this is an elementary question: I have a polyline whose 'Points' (type: PointsCollection) property is bound to a PointsCollection public member, Pts, in my view model class. When I add/remove points from ViewModel.Pts, the polyline redraws correctly without any problem. However, if I change Pts to be a reference to another, totally different PointsCollection object in my view model class, then the polyline doesn't automatically redraw. The