dependency-properties

How is dependency property implemented?

≡放荡痞女 提交于 2020-01-13 09:43:28
问题 Can anyone explain how is dependency property implemented? Is it just a static dictionary that is declared in base class with a reference of given instance as a key?I can't find any resources about this in internet... Thanks a lot 回答1: I see two questions: How do dependency properties work? The MSDN article on Properties in WPF is a great series on dependency properties. Should be a good overview to get you started. How are dependency properties implemented? You won't find any resources on

Quickly create dependency properties in VS

Deadly 提交于 2020-01-13 07:28:15
问题 Is there any way how to speed up dependency properties creating in VS? Like some template or refractoring option that will make dependency property out of normal one. Anything. I create a lot of dependency properties right now... Thank you for help 回答1: There are code snippets for dependency properties. (such as propdp ) See this article for more information. You can get some here. 回答2: The code snippet for DPs is propdp , enter that and hit tab twice, then cycle through the fields with tab

Dependency objects/properties from a DLL

≯℡__Kan透↙ 提交于 2020-01-13 07:15:54
问题 Here is the code I have : public class MyObject : DependencyObject { public int speedSimu { get { return (int)GetValue(speedSimuProperty); } set { SetValue(speedSimuProperty, value); } } public static readonly DependencyProperty speedSimuProperty = DependencyProperty.Register("speedSimu", typeof(int), typeof(MyObject), new PropertyMetadata(0)); public int Value { get; set; } } public class Timer : DependencyObject { public string description { get { return (string)GetValue(descriptionProperty

Why do some properties need a default defined in the style before a DataTrigger takes effect?

蓝咒 提交于 2020-01-13 03:22:27
问题 Why is it that some dependency properties need to have a default setter in the style before the triggered setters will take effect? For example, <ContentControl> <ContentControl.Resources> <DataTemplate x:Key="DefaultTemplate"> <TextBlock Text="Default Template" /> </DataTemplate> <DataTemplate x:Key="MouseOverTemplate"> <TextBlock Text="MouseOver Template" /> </DataTemplate> </ContentControl.Resources> <ContentControl.Style> <Style TargetType="{x:Type ContentControl}"> <!-- Triggered setter

Howcome the get/set in dependency property doesn't do anything?

六眼飞鱼酱① 提交于 2020-01-12 18:48:05
问题 I've created a dependency property like this: public partial class MyControl: UserControl { //... public static DependencyProperty XyzProperty = DependencyProperty.Register("Xyz",typeof (string),typeof (MyControl),new PropertyMetadata(default(string))); public string Xyz { get { return (string) GetValue(XyzProperty ); } set { SetValue(XyzProperty , value); } } //... } Then bind it to my wpf window and everything worked fine. When I tried to add some logic to the setter I notice it wasn't

Cannot bind DependencyProperty of type IList from both XAML and Setter

北慕城南 提交于 2020-01-11 12:50:29
问题 After implementing the propsed code from here: Cannot bind ObservableCollection to List dp from xaml I found out that if I had several instances of the control in the same page, the IList recieved all the values given to all the controls. I read online that in order to solve this, one must write: SetValue(...) in the constructor. This causes the Setter that is shown in above link not to work. (I guess that is because this time we need the IList to be static and not per-instance). Please help!

Register Property as DependencyProperty

末鹿安然 提交于 2020-01-11 09:59:08
问题 I have a UserControl called ChartView. There I have a Property of type ObservableCollection. I have implemented INotifyPropertyChanged in the ChartView. The code for a ChartEntry is: public class ChartEntry { public string Description { get; set; } public DateTime Date { get; set; } public double Amount { get; set; } } Now I want to use this Control in another View and setting the ObservableCollection for the ChartEntries through DataBinding. If I try to just do it with: <charts:ChartView

wpf dependency property enum collection

筅森魡賤 提交于 2020-01-11 07:22:07
问题 I have an enum listing all possible settings: public enum Settings { Settings1, Settings2, Settings3 } In my user control i want to implement a new depedency property that holds a list of settings and be able to use it like this: <my:Control Settings="Settings1, Settings2" /> How should i implement this? 回答1: public class StringDelimitedToEnumListConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { List<Settings> retval =

Behavior of DependencyProperty With Regards to Multiple FrameworkElement Instances

*爱你&永不变心* 提交于 2020-01-10 04:31:04
问题 So I tried using DependencyProperty to solve my issues with regards to passing the local ViewModel across child Views. However a question popped in my head. For example I need to make multiple instances of a certain FrameworkElement , say, a UserControl . That UserControl has a DependencyProperty defined. As stated in books, a dependency property instance should be static and readonly . How would the DependencyProperty work in that kind of scenario? Would it work the same way as a

Why do I get a DependencyProperty.UnsetValue when converting a value in a MultiBinding?

隐身守侯 提交于 2020-01-10 03:28:12
问题 I have an extremely simple IMultiValueConverter that simply OR's two values. In the example below, I want to invert the first value using an equally simple boolean inverter. <MultiBinding Converter="{StaticResource multiBoolToVis}"> <Binding Path="ConditionA" Converter="{StaticResource boolInverter}"/> <Binding Path="ConditionB"/> </MultiBinding> and the inverter: public class BoolInverterConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type