dependency-properties

Dependency Property Uses in WPF

霸气de小男生 提交于 2019-11-30 21:26:39
I am having a hard time figuring out good reasons for the dependency property. Why the System.Controls.TextBox "Text" property a dependency property and not a normal property? What benefits does it serve being a dependency property? One of the things I am trying to accomplish is to add a ValidationRules property to my UserControl which will contain other validation rules. Like here: <customControls:RequiredTextBox.ValidationRules> <validators:NotNullOrEmptyValidationRule ErrorMessage="FirstName cannot be null or empty"/> </customControls:RequiredTextBox.ValidationRules> The problem is that I

Must create DependencySource on same Thread as DependencyObject

走远了吗. 提交于 2019-11-30 20:04:35
I have an application written in wpf, which downloads some webpages, parses html code and saves some values. class ListOfItems { public List<SomeObject> ListToBind; public void DownloadItems() { Task.Factory.StartNew(() => { ... ... if (OnDownloadCompleted != null) OnDownloadCompleted(this, EventArgs.Empty); } } } class SomeObject { public string NameOfItem; public MyClass Properties; } class MyClass { public int Percentage; public SolidColorBrush Color; } This is the object model I'm using. It's simplified version and I don't want you to reorganize it, there is a reason I wrote it this way.

WPF: PropertyChangedCallback triggered only once

前提是你 提交于 2019-11-30 19:05:56
I have a user control, which exposes a DependencyProperty called VisibileItems Every time that property gets updated, i need to trigger another event. To achieve that, i added a FrameworkPropertyMetadata with PropertyChangedCallback event. For some reason, this event gets called only once, and doesn't trigger the next time VisibleItems is changed. XAML: <cc:MyFilterList VisibleItems="{Binding CurrentTables}" /> CurrentTables is a DependencyProperty on MyViewModel. CurrentTables gets changed often. I can bind another WPF control to CurrentTables, and i see the changes in the UI. Here is the way

Custom Control Dependency Property Binding

痞子三分冷 提交于 2019-11-30 17:20:30
I am going insane trying to get this to work with even the most basic example. I cannot for the life of me get binding to work. Here is a super easy example that is not working for me. I MUST be doing something incorrect. My Custom Control in my control library assembly: public class TestControl : Control { public static readonly DependencyProperty TestPropProperty = DependencyProperty.Register("TestProp", typeof(string), typeof(TestControl), new UIPropertyMetadata(null)); public string TestProp { get { return (string)GetValue(TestPropProperty); } set { SetValue(TestPropProperty, value); } }

What is a dependency property? What is its use? [duplicate]

走远了吗. 提交于 2019-11-30 17:14:12
Possiblity: What is a dependency property? What is a dependency property? How does it differ from a normal property? What is the purpose of dependency properties? And why it is used, when it is used? Dependency property : A property that is backed by a DependencyProperty . The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs . These other inputs might include system properties such as themes and user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use

What is a dependency property? What is its use? [duplicate]

怎甘沉沦 提交于 2019-11-30 16:31:53
问题 This question already has answers here : Closed 8 years ago . Possiblity: What is a dependency property? What is a dependency property? How does it differ from a normal property? What is the purpose of dependency properties? And why it is used, when it is used? 回答1: Dependency property : A property that is backed by a DependencyProperty . The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs . These other inputs might

Custom Control Dependency Property Binding

妖精的绣舞 提交于 2019-11-30 16:26:24
问题 I am going insane trying to get this to work with even the most basic example. I cannot for the life of me get binding to work. Here is a super easy example that is not working for me. I MUST be doing something incorrect. My Custom Control in my control library assembly: public class TestControl : Control { public static readonly DependencyProperty TestPropProperty = DependencyProperty.Register("TestProp", typeof(string), typeof(TestControl), new UIPropertyMetadata(null)); public string

Dependency Property is not updating my Usercontrol

℡╲_俬逩灬. 提交于 2019-11-30 14:57:20
问题 The line below works for the TextBox DP Text , where CellNo is a property of a class which derives from INotifyPropertychanged. So here when I change the CellNo the Text will be updated and When I change the CellNo the Text will be updated. This will work fine. Text="{Binding Path = CellNo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" I have create a user control which contain only one TextBox. I have defined one DP name CellValue as below: public string CellValue { get { return (string

Difference between CoreceValueCallback and ValidateValueCallback?

女生的网名这么多〃 提交于 2019-11-30 14:15:24
问题 I know that CoerceValueCallback is used to correct a value and that ValidateValueCallback will return true or false. But my question is why we need ValidatevalueCallback ? We can simply use CoerceValueCallback to validate (using if condition) and correct the value. Can you give some practical example of when to use coercion vs. validation? 回答1: Value coercion is basically to change the value, if the the new value is not as system expected. A best example is Slider control. A Slider has both

Defining InputBindings within a Style

泄露秘密 提交于 2019-11-30 11:04:25
I'm creating a WPF app using the MVVM design pattern, and I'm trying to extend the TabItem control so that it closes the tab when the user clicks the middle mouse button. I'm trying to achieve this using InputBindings, and it works very well until I try to define it within a style. I've learned that you cannot add InputBindings to a style unless you attach it using a DependencyProperty. So I followed this similar post here... and it works... almost. I can close one tab using the middle mouse button, but it won't work on any of the other tabs (all of the tabs are added at runtime and inherit