dependency-properties

Template Binding for Custom Attached Property

断了今生、忘了曾经 提交于 2019-12-03 21:13:40
问题 I am trying to use an Image in Button Control which animates on Hover and Pressed state by showing different images. Accordingly, I have defined 3 attached properties for the Button Control as given below. public class ButtonExtensions : DependencyObject { public static DependencyProperty ImageSourceProperty = ... public static DependencyProperty ImageHoverSourceProperty = ... public static DependencyProperty ImagePressedSourceProperty = DependencyProperty.RegisterAttached("ImagePressedSource

How can I create a custom *write-only* dependency-property?

天涯浪子 提交于 2019-12-03 20:09:23
I need to know what the procedure is for making a write-only dependency-property. I can see that the DependencyProperty class does not have a special "Register" method for write-only properties, but I have no idea whether the RegisterAttached method may apply to what I am trying to do. This property needs to be a dependency-property, rather than a simple CLR property. Internally, my class requires a PropertyChangedCallback on this property in order to remain stable. I know that write-only dependency-properties can be created, because it is stated quite clearly in: Pro C# 2008 and the .NET 3.5

Force Propagation of Coerced Value

Deadly 提交于 2019-12-03 17:37:08
问题 tl;dr: Coerced values are not propagated across data bindings. How can I force the update across the data binding when code-behind doesn't know the other side of the binding? I'm using a CoerceValueCallback on a WPF dependency property and I'm stuck at the issue that coerced values don't get propagated through to bindings. Window1.xaml.cs using System; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; namespace CoerceValueTest { public

Cannot databind DependencyProperty

天大地大妈咪最大 提交于 2019-12-03 17:10:19
I have a UserControl with a DependencyProperty. I set it's value in the host window using a data binding expression. However, it doesn't work as expected. Snippet from the user control's codebehind: public class ViewBase : UserControl { public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register( "ViewModel", typeof(ViewModelBase), typeof(ViewBase)); public ViewModelBase ViewModel { get { return GetValue(ViewModelProperty) as ViewModelBase; } set { SetValue(ViewModelProperty, value); } } } And from the XAML (note: CasingListView inherits from ViewBase):

Creating a bindable Point in C# WPF

旧时模样 提交于 2019-12-03 14:59:30
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 following code is provided as wishful thinking and I understand that it will in no way work, but this is

Setting up binding to a custom DependencyProperty inside a WPF user control

亡梦爱人 提交于 2019-12-03 13:07:31
I have a WPF UserControl containing a custom DependencyProperty named MyDP. I want to bind this to a property on my ViewModel (which is injected as the UserControl's DataContext). I know one way to do it by setting the binding in the UserControl's declaration in the parent window's XAML as such: <Window x:Class="MyNamespace.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:views="clr-namespace:MyNamespace.Views"> <StackPanel> <views:MyControl MyDP="{Binding Path=MyVMProperty, Mode=OneWayToSource}"/>

How does the WPF dependency property design save memory consumption?

痞子三分冷 提交于 2019-12-03 12:40:55
问题 I read this in the following link:- http://www.informit.com/articles/article.aspx?p=688529&seqNum=2 However, because GetValue and SetValue internally use an efficient sparse storage system and because IsDefaultProperty is a static field (rather than an instance field), the dependency property implementation saves per-instance memory compared to a typical .NET property. If all the properties on WPF controls were wrappers around instance fields (as most .NET properties are), they would consume

WPF override IsEnabled from Parent

和自甴很熟 提交于 2019-12-03 11:24:27
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.OverrideMetadata(typeof(FrameworkElement), new UIPropertyMetadata(true,IsEnabledChanged, CoerceIsEnabled));

Multiple user controls share collection dependency property

牧云@^-^@ 提交于 2019-12-03 11:13:06
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.microsoft.com/winfx/2006/xaml" Name="_simpleList"> <StackPanel> <TextBlock Text="{Binding Path=Title,

How to simply bind this to ConverterParameter?

偶尔善良 提交于 2019-12-03 10:50:19
问题 I have problem and i don't know how to solve this simple, i have many points like this, then solution should be not complicated. I have main project with Settings and main XAML. I have dependency project with Binding Converter and XAML File looks like: <TextBlock Text="{Binding X.Y.Z, Converter={StaticResource ProbabilityConverter}, ConverterParameter=??????????????, Mode=OneWay}" /> This XAML file is loading by main XAML file from main project. I must pass value of one property from Setting