dependency-properties

Two-way binding in AvalonEdit doesn't work

。_饼干妹妹 提交于 2019-11-29 04:12:17
I have used AvalonEdit in my project that is based on WPF and MVVM. After reading this post I created the following class: public class MvvmTextEditor : TextEditor, INotifyPropertyChanged { public static DependencyProperty DocumentTextProperty = DependencyProperty.Register("DocumentText", typeof(string), typeof(MvvmTextEditor), new PropertyMetadata((obj, args) => { MvvmTextEditor target = (MvvmTextEditor)obj; target.DocumentText = (string)args.NewValue; }) ); public string DocumentText { get { return base.Text; } set { base.Text = value; } } protected override void OnTextChanged(EventArgs e) {

Any way to un-register a WPF dependency property?

若如初见. 提交于 2019-11-29 04:09:51
I'm running into an unusual problem in my unit tests. The class I'm testing creates a dependency property dynamically at runtime and the type of that dependency property can vary depending on the circumstances. While writing my unit tests, I need to create the dependency property with different types and that leads to errors because you can't redefine an existing dependency property. So is there any way to either un-register a dependency property or to change the type of an existing dependency property? Thanks! OverrideMetadata() only lets you change a very few things like default value so it

How can I fix the DependencyPropertyDescriptor AddValueChanged Memory Leak on AttachedBehavior?

烈酒焚心 提交于 2019-11-29 04:06:40
I know I need to call RemoveValueChanged, but I have not been able to find a reliable place to call this. I'm learning that there probably isn't one. I looks like I need to find a different way to monitor the change then adding a handler using AddValueChanged. I'm looking for advice on the best way to achieve this. I've seen the recommendation of using a PropertyChangedCallback in the PropertyMetadata, but I'm not sure how to do this when my TextBox and Adorner are not static. Also, the IsFocused property is not a DependencyProperty created in my class. Thanks. public sealed class

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

萝らか妹 提交于 2019-11-29 02:23:22
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)(GetValue(DepProp))); } set { SetValue(DepProp, value); } } However, when I add the default value to

Add dependency property to control

六眼飞鱼酱① 提交于 2019-11-29 02:09:41
I am using the Infragistics XamDateTimeEditor control and I want to add a dependency property to it to allow the developer to choose to have all the text selected when the control gets focus. I have created a style that is used to set the behavior I want but I want the developer to decide if the behavior should be executed based on a boolean dependency property. I am not sure how that is done. Denis Troller I assume you inherited from XamDateTimeEditor for this. If you can write the code referencing a "standard" (clr) property, then you are good to go: declare your DependencyProperty remove

What are the defaults for Binding.Mode=Default for WPF controls?

瘦欲@ 提交于 2019-11-28 23:32:11
问题 In WPF Binding.Mode, when selecting Default, it depends in the property being binded. I am looking for some list or some convention or any information for the defaults for the various controls. I mean, what properties are TwoWay by default and so on. Any links, ideas, thoughts and even rants are welcommed! 回答1: Similar to UpdateSourceTrigger, the default value for the Mode property varies for each property. User-editable properties such as TextBox.Text , ComboBox.Text , MenuItem.IsChecked ,

Binding to custom dependency property - again

狂风中的少年 提交于 2019-11-28 21:17:41
OK, i know. This has been asked literally one million times, but i still don't get it. Sorry for that. The task: implement the simplest Dependency Property ever, which can be used in xaml like that: <uc:MyUserControl1 MyTextProperty="{Binding Text}"/> I think that this answer is quite close. For better readability i copy all my code here (mostly from that answer above). <UserControl x:Class="Test.UserControls.MyUserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup

Wpf UserControl and MVVM

ぐ巨炮叔叔 提交于 2019-11-28 20:25:50
I am thinking about writing a WPF User Control for my application. I am using MVVM in my application. User control's may require Dependency Properties that can be set my Parent View. when using MVVM, the idea is that the Parent View will eventually create a binding between the UserControls DP with Parent View's VM) Dependency Properties need to be created in the View class as VM do not inherit from DependencyObject . This means adding code within the XAML code behind. I was wondering if you can give advice as to how I should design a user control when developing WPF application using MVVM...

How do You Create a Read-Only Dependency Property?

こ雲淡風輕ζ 提交于 2019-11-28 16:37:55
How do you create a read-only dependancy property? What are the best-practices for doing so? Specifically, what's stumping me the most is the fact that there's no implementation of DependencyObject.GetValue() that takes a System.Windows.DependencyPropertyKey as a parameter. System.Windows.DependencyProperty.RegisterReadOnly returns a D ependencyPropertyKey object rather than a DependencyProperty . So how are you supposed to access your read-only dependency property if you can't make any calls to GetValue? Or are you supposed to somehow convert the DependencyPropertyKey into a plain old

Simple Dependency Property and UserControl issues in C#

北城以北 提交于 2019-11-28 14:19:32
My end goal is to expose the Text value of a TextBox that I have in a UserControl , from the UserControl 's call in XAML. <my:UserControl SetCustomText="Blah blah this is variable"> would render the UserControl with that TextBox 's text filed in. I've been working at it using various examples but I always end up with "The Property SetCustomText was not found in type UserControl" Example of how you can do this: <UserControl x:Class="Test.UserControls.MyUserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc=