dependency-properties

Limit attached dependency property in wpf

孤街醉人 提交于 2019-12-05 00:52:29
I want to attach a dependency property to specific controls only. If that is just one type, I can do this: public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.RegisterAttached("MyProperty", typeof(object), typeof(ThisStaticWrapperClass)); public static object GetMyProperty(MyControl control) { if (control == null) { throw new ArgumentNullException("control"); } return control.GetValue(MyPropertyProperty); } public static void SetMyProperty(MyControl control, object value) { if (control == null) { throw new ArgumentNullException("control"); } control.SetValue

Creating a bindable Point in C# WPF

假如想象 提交于 2019-12-04 21:20:29
问题 I know multiple inheritence is out, but is there a way to create a wrapper for System.Windows.Point that can inherit from it but still implement bindable dependency properties? I'm trying to code so that for my XAML I can create staments like the following without issue: <custom:Point X="{Binding Width, ElementName=ParentControlName}" Y="{Binding Height, ElementName=ParentControlName}" /> It would make coding things like Polygons, Paths, LineSegments and other controls so much easier. The

WPF Custom Control, DependencyProperty issue

淺唱寂寞╮ 提交于 2019-12-04 20:08:17
Ive got a test code setup with the custom control: /// <summary> /// Interaction logic for UCTest.xaml /// </summary> public partial class UCTest : UserControl { public static readonly DependencyProperty LastNameProperty = DependencyProperty.Register("LastName", typeof(string), typeof(UCTest), new PropertyMetadata("No Name", LastNameChangedCallback, LastNameCoerceCallback), LastNameValidateCallback); private static void LastNameChangedCallback( DependencyObject obj, DependencyPropertyChangedEventArgs e) { Console.WriteLine(e.OldValue + " " + e.NewValue); } private static object

Is it possible to use compiled binding (x:Bind) with Relative Source, Templated Parent

佐手、 提交于 2019-12-04 17:53:08
I'd like to do something like this is a Style: Value="{x:Bind MyCustomDependencyProp, RelativeSource={RelativeSource TemplatedParent}}" Is that possible? Are there any performance benefits? Using TemplateBinding does not seem to work, with a custom DependencyProperty as described elsewhere here on SO: https://stackoverflow.com/a/8657453 RelativeSource (with x:Bind) is not supported, therefore this particular scenario won't be possible (at the moment, at least). Using TemplateBinding or standard Binding to TemplatedParent (as you mentioned) are workarounds. TemplateBinding is already an

Multiple user controls share collection dependency property

試著忘記壹切 提交于 2019-12-04 17:41:56
问题 I have implemented my own usercontrol based on listboxes. It has a dependency property with type of a collection. It works fine when I have only one instance of the usercontrol in a window, but if I have multiple instances I get problem that they share the collection dependency property. Below is a sample illustrating this. My user control called SimpleList: <UserControl x:Class="ItemsTest.SimpleList" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas

WPF override IsEnabled from Parent

五迷三道 提交于 2019-12-04 16:25:22
问题 I just searched for a way to enable a child control while the parent control has IsEnabled = false . All answers that I have found up to now say that it is not possible - one has to enable the parent and disable the child controls except the ones that should still be enabled. However, by overriding the Metadata for the IsEnabledProperty in the App.xaml.cs file, I was able to change this default behavior: protected override void OnStartup(StartupEventArgs e) { UIElement.IsEnabledProperty

Base class DependencyProperty value change in WPF

安稳与你 提交于 2019-12-04 14:09:46
I have a DependencyProperty in the ClassA. I derived another ClassB from ClassA. When the value of this property is updated or changed in ClassA, How it can be notified or reflected in the derived ClassB with out adding any additional code in ClassA ? By registering a PropertyChangedCallback for ClassB through DependencyProperty.OverrideMetadata in the derived class: class ClassB { static ClassB() { ClassA.SomeValueProperty.OverrideMetadata( typeof(ClassB), new PropertyMetadata(SomeValuePropertyChanged); } private static SomeValuePropertyChanged( DependencyObject o,

Custom Control for DataGridTemplateColumn

£可爱£侵袭症+ 提交于 2019-12-04 13:31:28
问题 I'm currently attempting to create a custom control out of a DataGridTemplateColumn that will be reused across many of our applications. I'm running into some issues getting a dependency property on the custom control to bind and raise the property changed notification correctly. I currently have the control inheriting from DataGridTemplateColumn the xaml looks like this: <DataGridTemplateColumn x:Class="Controls.DataGridDateColumn" xmlns="http://schemas.microsoft.com/winfx/2006/xaml

MVVM + UserControl + Dependency Property

旧街凉风 提交于 2019-12-04 08:10:19
Alright, this is somewhat related to this question: WPF Printing multiple pages from a single View Model I tried to follow the advice given there but now I am stuck. My application uses a MainView.xaml and the appropriate MainViewViewModel.cs, I am using MVVM Light in the background. Now - according to the post - it seems I have to do the following: Create a user control Expose some properties from the user control Make sure the view model shows these properties The idea is clear but I am stuck when trying to notify each other. My user control (UcTest.xaml) exposes a Dependency Property:

How Dependency Property tell the object to apply to?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 08:09:22
(I am totally new to this concept so I may be asking very basic questions.) A dependency property is registered with the code below: public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata); Logically, it did nothing but associate a property name with the owner type. So if I have multiple instances of the owner type, and each instance set the DP to different values. How could these values be stored? Update 1 - 10:04 AM 10/30/2013 I read about the Attached Property from here: http://wpftutorial.net/DependencyProperties.html