dependency-properties

Force update notifications for DependencyProperty even when it doesn't change

非 Y 不嫁゛ 提交于 2019-12-11 04:47:11
问题 I have a custom WPF control. It has a typical DependencyProperty , let's call it Status , which is updated periodically via binding. (More specifically, it is bound to a property which sends notifications according to INotifyPropertyChanged ). I want to implement a certain 'expiration' behaviour: if Status is not updated for a certain time, something happens. Ideally, this logics should be within my custom control (I have many instances of it). I set up a DispatcherTimer in the Status change

Growing UserControl Size with Style Trigger?

允我心安 提交于 2019-12-11 03:49:28
问题 I would like to cause a custom UserControl to grow by a multiplier when an "IsSelected" DP is set to true. My current XAML looks like this: <ctrl:MyBaseControl x:Class="MyDemo.Controls.MyCustomControl" ...> <ctrl:MyBaseControl.Resources> <Style TargetType="{x:Type ctrl:MyCustomControl}"> <Setter Property="BorderBrush" Value="White" /> <Style.Triggers> <Trigger Property="IsSelected" Value="True"> <Setter Property="BorderThickness" Value="2" /> <Setter Property="Width" Value="340" /> <Setter

Dependency property callback does not work

╄→гoц情女王★ 提交于 2019-12-11 03:05:51
问题 I have the following code: private static readonly DependencyProperty IDProperty = DependencyProperty.Register( "ID", typeof(int), typeof(DetailDataControl), new PropertyMetadata(-1, new PropertyChangedCallback(IDChanged))); public int ID { get { return (int)GetValue(IDProperty); } set { SetValue(IDProperty, value); } } private static void IDChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // Do something here! } I can see that when I change ID, the line SetValue(IPproperty

Reading Attached Property from Non-DependencyObject

大憨熊 提交于 2019-12-11 02:49:41
问题 XAML lets me attach properties to types that are not derived from DependencyObject. For example, I could give names to the CommandBindings on a Window: <Window.CommandBindings> <CommandBinding x:Name="Refresh" Command="NavigationCommands.Refresh" /> <CommandBinding x:Name="Print" Command="ApplicationCommands.Print" /> </Window.CommandBindings> I found mention of this possibility on MSDN (Attached Properties Overview), which states " If your class is defining the attached property strictly for

Delayed “rendering” of WPF/Silverlight Dependency Properties?

佐手、 提交于 2019-12-11 02:18:35
问题 Is there a way to know the first time a Dependency Property is accessed through XAML binding so I can actually "render" the value of the property when needed? I have an object (class derived from Control) that has several PointCollection Dependency Properties that may contain 100's or 1000's of points. Each property may arrange the points differently for use in different types shapes (Polyline, Polygon, etc - its more complicated then this, but you get the idea). Via a Template different XAML

Dependency Property Datacontext

孤者浪人 提交于 2019-12-11 02:06:48
问题 I have a usercontrol, and there is a Datacontext set for it. This usercontrol contains also a Dependency-Property. Now, i want simply bind to this property. I think the problem has something to do with the wrong datacontext. The dependency-Property in my usercontrol (called TimePicker) looks like this: public TimeSpan Time { get { return (TimeSpan)GetValue(TimeProperty); } set { SetValue(TimeProperty, value); OnPropertyChanged(); } } public static readonly DependencyProperty TimeProperty =

What are the reasons/scenarios for properties like DisplayMemberPath to be dependency properties?

末鹿安然 提交于 2019-12-11 01:34:53
问题 Could anyone explain the reasoning behind making say ItemsControl.DisplayMemberPath a dependency property and not just a regular CLR property? Are there any real life scenarios when such properties are used in data binding scenarios, styles, or other dependency property related situations. Thanks. Update: The reason for this question are statements like Making your property a dependency property is not always necessary or appropriate and will depend on your needs. Sometimes, the typical

Synchronizing Dependency Properties (View) with Properties (ViewModel)

馋奶兔 提交于 2019-12-10 23:04:10
问题 Does anybody know how I can synchronize my properties, which are in a ViewModel, with my Dependency Properties, which are in the View? I am trying to make a UserControl, which will then be hosted by a WPF-Window (MainWindow.xaml). The UserControl has an own ViewModel which contains ICommands and properties. The problem is, that I also have to return certain properties to the MainWindow(.xaml) and also set them. Currently my classes are looking like that: MainWindow.xaml <TextBox Name="tbInput

Why “propdp” code snippet doesn't use the nameof operator for the name of the registered property?

走远了吗. 提交于 2019-12-10 14:19:09
问题 If you insert the snippet propdp , it doesn't use the nameof operator for the property name in the first parameter of the DepencendyProperty.Register method and it creates something like this: public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextProperty = DependencyProperty.Register(

IEnumerable DependencyProperty throws errors when set in XAML

三世轮回 提交于 2019-12-10 12:17:42
问题 I have a custom control Workspace that inherits from Control and within it is a DependencyProperty that I need to contain a user-specified IEnumerable<IFoo> (I have also tried making it an non-generic IEnumerable ). Public Shared ReadOnly FoosProperty As DependencyProperty = DependencyProperty.Register("Foos", GetType(IEnumerable(Of IFoo)), GetType(Workspace), New FrameworkPropertyMetadata()) Public Property Foos() As IEnumerable(Of IFoo) Get Return CType(Me.GetValue(FoosProperty),