dependency-properties

How do I reset a DependencyProperty back to it's default value in XAML

隐身守侯 提交于 2019-12-11 13:34:02
问题 I'm implementing a user-adjustable Effect using sliders and I have a reset button beside the slider. The idea is to allow the user to reset back to the default value of the Effect 's property as specified in metadata. I think it might be trivial to do that in XAML. 回答1: Dependency properties don't really have default values. If a dependency property doesn't have a local value, it will obtain its value either through value inheritance or through coercion, depending on how the property has been

How VerticalOffset changes when Scrollable height changes while having list inside a list

天大地大妈咪最大 提交于 2019-12-11 12:43:38
问题 I am making a WP7 app which has a Listbox of UserControls. Each UserControl has an ItemsControl and Button(for getting more results). On click of the button the ItemsControl items will be increased by 5 or 10. Now on clicking on the GetMore button of any of the usercontrols except the first or last, there will be an increase in Scrollable height(Total height of the listbox) of the ListBox but the VerticalOffset(position of scrollbar from top) of the ListBox remains same. Now the problem I am

Attached or dependecy Property for ValidationRule WPF

风格不统一 提交于 2019-12-11 12:14:08
问题 I want to bind the attached property or dependency property in xaml for the ValidationRule in xaml and then based on the value of the attached property or dependency property I want to make sum decision in the Validation rule. I can't find any solution how can I Pass bindable value to the Validation Rule. 回答1: I supply you a sample code to help you. I have defined a ValidationRule to validate a texbox user input. The type of validation is performed according value of one enum parameter. Type

How do I implement a DependencyProperty on a custom wpf control for an ImageSource?

吃可爱长大的小学妹 提交于 2019-12-11 10:47:24
问题 How do I implement a DependencyProperty on a custom wpf control for an ImageSource ? I created a custom control (button) which amongst other things does display an image. I want to be able to set the ImageSource for the image from the outside of the control, so I implemented a DependencyProperty. Whenever I try to change the ImageSource though, I am getting a SystemInvalidOperationException : "The calling thread cannot access this object because a different thread owns it." OK, so the main

Dependency property default value not being overriden

ⅰ亾dé卋堺 提交于 2019-12-11 10:02:23
问题 I am trying to override the value of a dependency property but it doesn't seem to be working. In my Xaml code I have a button with the following CommandParameter : CommandParameter="{Binding State,Mode=OneWay} and here I declare my dependency property: public class MyStateControl : UserControl { public MyStateControl() { this.InitializeComponent(); } public string State { get { return (string)this.GetValue(StateProperty); } set { this.SetValue(StateProperty, value); } } public static readonly

Textbox value changed from Viewmodel not reflected on UI

老子叫甜甜 提交于 2019-12-11 09:24:12
问题 I have a textbox, text is bound to a property in ViewModel. User can either manually enter the text or paste it from clipboard. I parse the text (I use UpdateSourceTrigger=PropertyChanged ) entered by the user and split the text by newline char. Problem : When user hits enter, everything works fine. But when I try to process the pasted text, as soon as I see first "\n", I try to break it into different strings and clear the textbox. In ViewModel, text is set to string.empty, but it is not

Using multibinding to set custom attached property in WPF

耗尽温柔 提交于 2019-12-11 08:14:51
问题 I have a MVVM WPF project where I am attempting to set the value of a custom attached property using a multiconverter, which should be passed a property of the DataContext (ViewModel) and another custom attached property on the element. I can bind the property to the viewmodel directly using the xaml attribute syntax, but I'm having trouble understanding how to set the value of the attached property using a multiconverter. <StackPanel> <StackPanel.Resources> <example:HelpTextConverter x:Key=

PropertyChangedCallback on DependencyProperty Only Firing Once

北城以北 提交于 2019-12-11 07:00:11
问题 I have the exact problem as this guy in the Silverlight Forum and the accepted answer is : In this case, your property didn't actually change value. You added something to your List, but the list is the same List so when the DependencyProperty mechanism sees that the actual value (reference to your List) didn't change, it didn't raise your OnChanged handler This is a great explication but not an answer to fix this problem. I can find on Google many suggestion for WPF but not for Silverlight.

How can I bind to dependency properties of a custom control from a resource dictionary defined in Generic.xaml?

青春壹個敷衍的年華 提交于 2019-12-11 06:37:26
问题 EDIT: I rephrased the entire question. Hello everybody, I have a custom control with dependency properties. In the Generic.xaml file I have a resource dictionary. It's a resource dictionary within the outer dictionary, defined like so: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyNamespace"> <!-- This is the dictionary--> <ResourceDictionary x:Name=

In WPF, for a DP, is there any way to use a function to return the default value or to have a CoerceValue on the getter side?

ぃ、小莉子 提交于 2019-12-11 06:05:59
问题 There's an exceptional case in WPF where I need to set a dependency property via XAML that actually doesn't get stored itself, but rather is used to set other dependency properties. This is pretty easy since I just use the CoerceValue to intercept the change, do what I want with the passed-in value, then cancel the change on that property. This means when I get that property, I'll still get the default value since I blocked the actual change. Works great. As an example, when I set this faux