FAQ Database Discussion Community


Dependency Property Datacontext

c#,wpf,dependency-properties
I have a usercontrol, and there is a Datacontext set for it. This usercontrol contains also a Dependency-Property. Now, i want simply bind to this property. I think the problem has something to do with the wrong datacontext. The dependency-Property in my usercontrol (called TimePicker) looks like this: public TimeSpan...

WPF C# Callback when dependency property recieves xaml change

c#,wpf,xaml,dependency-properties
When I set the value of IsClosed during runtime, OnIsClosedChanged() is called fine. However, the Designer sets the value of the property but does not call the OnIsClosedChanged(). public static DependencyProperty IsClosedProperty = DependencyProperty.Register("IsClosed", typeof(bool), typeof(GroupBox), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); public bool IsClosed { get { return (bool)this.GetValue(IsClosedProperty); } set {...

SetValue makes dependencyProperty null

c#,wpf,dependency-properties
I am trying to set a value on my dependency property but it always sets null. [Description("Binded destination list"), Category("Data")] public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("DestinationList", typeof(IEnumerable<TestEntity>), typeof(ListBoxEditLookup), new FrameworkPropertyMetadata(IsDestinationListChangedCallback) { BindsTwoWayByDefault = true, DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged}); public IEnumerable<TestEntity> DestinationList { get { return...

DependencyProperty of type ObservableCollection doesn't bind

c#,wpf,observablecollection,dependency-properties
I am trying to make a custom control with a DependencyProperty. But I cannot bind my ObservableCollection to the control. When I use an Enumerable I have no problem. But I need to add items to the collection so my only option is ObservableCollection. Creating Authorizations: AuthorizationsDest = new ObservableCollection<Authorization>();...

F# Creating a UserControl Programmatically: Missing Update (keyboard input seem locked)

wpf,f#,event-handling,wpf-controls,dependency-properties
I have tried to create a "UserControl" "By-Code" only, using F# (Vers. 12.0.30815.0 + Framework 4.5) since I prefer this "way" (no mix between C# and F#). NOTE: I have to show multiple properties of a single Class in an Input Form, so this UserControl need to implement Binding capabilities...

Property not change on two way binding mode with dependency property

c#,wpf,mvvm,dependency-properties
I have the following dependency property: public bool UndoZoom { get { return (bool)GetValue(UndoZoomProperty); } set { SetValue(UndoZoomProperty, value); } } // Using a DependencyProperty as the backing store for UndoZoom. This enables animation, styling, binding, etc... public static readonly DependencyProperty UndoZoomProperty = DependencyProperty.Register("UndoZoom", typeof(bool), typeof(ZoomBehavior), new PropertyMetadata(false, new PropertyChangedCallback(OnUndoZoomChanged)));...

Manually invoking OnPropertyChanged for custom DependencyProperty

c#,wpf,dependency-properties
So I've got a custom DependencyProperty like this: public class PatientLookUp : TextBox { public static readonly DependencyProperty PatientProperty = DependencyProperty.Register("Patient", typeof(Patient), typeof(PatientLookUp), new FrameworkPropertyMetadata { BindsTwoWayByDefault = true }); public Patient Patient { get { return (Patient)GetValue(PatientProperty); } set { SetValue(PatientProperty, value); } } //some logic for getting the...

WPF - Attaching a custom property to a slider

c#,wpf,slider,dependency-properties,attached-properties
In my project, I am currently creating a slider in my code-behind the view and this slider has an event for when it's value changes. The place where the slider is created also has a custom object that is required for this project. I wanted to have this custom object...

Defining a Property in a IValueConverter class

wpf,dependency-properties,ivalueconverter
I need to define a DependencyProperty in a converter class because I need this data to make the conversion and this data is in another object, not the one I'm binding to. My converter class is the following: public class LEGOMaterialConverter : DependencyObject, IValueConverter { public DependencyProperty MaterialsListProperty = DependencyProperty.Register("MaterialsList",...

DependencyProperty in DataTemplate not working

c#,wpf,extension-methods,dependency-properties
I have an issue which is driving me crazy. I have a dependecyproperty, Uid, in an extensionclass. I this to set a static "language" string (tools:TranslateExtension.Uid="MAINWINDOW_ARTICLES"). I then use the Text="{tools:Translate}" to trigger a lookup for the set language. This will call ProvideValue method which will set up a binding....

How to bind custom dependecy property to control's view model?

c#,wpf,dependency-properties
I need to create a control with few inputs / output with lots of internal functionality. I think the best approach is to create Dependency Properties for interaction with other application parts and have a private view model with hidden functions. Here is my sample: Window <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"...

Custom Control DataBinding wpf

wpf,wpf-controls,custom-controls,dependency-properties
Currently implementing a custom control I would like to bind some Value directly from my viewModel without using xaml. I can do this: <customControls:MyControl MyValue="{Binding ElementName=MyElem, Path=Text}"> <Textbox Text="{Binding Mytext}" /> But not: <customControls:MyControl MyValue="{Binding MyText}"> The controls is defined in a template and inside the Control code my the...

Can i create SelectedItems Property for multiselect combobox

c#,wpf,dependency-properties,multi-select
Currently I am working on multiselect combobox custom control with combobox inherited, which attached a listbox to a combobox with a multiple selection mode. But now I face a problem when passing the selected items to my custom control in view. I use the listbox selectionchanged event to update my...

Caliburn Micro not updating dependency property in User Control

c#,wpf,mvvm,dependency-properties,caliburn.micro
I have a Caliburn Micro View/ViewModel set which is utilizing a User Control which has one of its dependency properties bound to a value which is in the ViewModel of the main view. I can't seem to get the User Control to be notified when the value in the ViewModel...

Unset dependency on binding to dependency property

c#,wpf,dependency-properties
I am trying to bind to a dependency property of my user control from my user control however it doesn't seem to be working as the converter keeps throwing an unset dependency property error The dependency property public DateTime? DisplayedDate { get { return (DateTime?)base.GetValue(DisplayedDateProperty); } set { base.SetValue(DisplayedDateProperty, value);...

Using a Dependency Property in a Data Trigger

c#,wpf,xaml,dependency-properties,datatrigger
I have the following custom control: public class AnimatedButton : Button { public enum ButtonStates { None, Busy } public ButtonStates State { get { return (ButtonStates)GetValue(StateProperty); } set { SetValue(StateProperty, value); } } // Using a DependencyProperty as the backing store for State. This enables animation, styling, binding, etc......

Bind to or Expose IsMouseOver or any other ReadOnly DependencyProperty from element inside UserControl

c#,wpf,xaml,dependency-properties,ismouseover
I have a window with a UserControl, that UserControl has an element. If I move the mouse over the element inside the UserControl, I want that some other elements inside the Window to react (for example: hide them). <Window x:Class="WpfApplication4.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:local="clr-namespace:WpfApplication4" > <DockPanel> <Grid Width="50"...

When using a DependencyProperty, how can I tell the the difference between an inherited value and an assigned one

c#,wpf,dependency-properties
The DependencyProperty system is really useful in a number of ways, but one which is causing me a little trouble at the moment is, with the DataContext property, doing some type checking. See below for my current approach, which already stops invalid types from causing weird magic-sting-namespace-collisions, but won't actually...

Set DependencyProperty Value in Changed Callback

c#,wpf,mvvm,dependency-properties
I have a DependencyProperty in my UserControl that uses a boolean to trigger a behaviour. In this case it is a UserControl designed to expose the feature of a SaveFileDialog and it uses a DialogVisible DependencyProperty. When the property is set to true I call the ShowDialog method on the...

Cannot convert lambda expression to type 'System.Delegate', Because it is not a delegate type

c#,lambda,dependency-properties
I define a dependency Property for my class1, which raise an event. I don't know why it give me this error "Cannot convert lambda expression to type 'System.Delegate'" public static readonly DependencyProperty class1Property = DependencyProperty.Register("class1Property", typeof(Class1), typeof(UserControl1), new PropertyMetadata(null)); public Class1 class1 { get { return Dispatcher.Invoke((() => GetValue(class1Property)))as Class1;...

How to bind to a property of a UserControl in WPF?

wpf,mvvm,data-binding,user-controls,dependency-properties
I'm trying to bind to a property of a user control, but it doesn't seem to work. <Controls:BasicFilter Title="Some title" FilterLists="{Binding LocationFilterLists}"/> FilterLists is the property I'm trying to bind to. Title property contains a text which is shown on a label within my control and this works well. I've...

Creating Items DP for charting user control

c#,wpf,binding,observablecollection,dependency-properties
I am busy creating a user control that has some basic charting/graph functions. In essence I want to have an "Items" dependency property to which the user of the control can bind. The control will then display all the items and updates made to the source. What I have done...

Dependency Property in F# Default Value does not match

c#,f#,dependency-properties
I am trying to convert a C# Dependency Property that limits the maximum length of text entered into a ComboBox to F#. The program is a MVVM program that uses F# for the model and viewmodel, and C# for the view. the working C# code is this: public class myComboBoxProperties...

Trouble Parameterizing ValidationRules with Dependency Properties

wpf,dependency-properties,validationrules
so I have written the following DP and ValidationRule: public class ComparisonValue : DependencyObject { public Object ComparisonObject { get { return (Object)GetValue(ComparisonObjectProp); } set { SetValue(ComparisonObjectProp, value); } } public static readonly DependencyProperty ComparisonObjectProp = DependencyProperty.Register("ComparisonObject", typeof(object), typeof(ComparisonValue), new UIPropertyMetadata(null)); } public class ObjectComparisonValidator : ValidationRule { private ComparisonValue...

Trigger vs. Dependency Property precendence

c#,.net,wpf,triggers,dependency-properties
I've got a question about the precendence of dependency property value. My .xaml looks lik the following: <Window x:Class="WpfTests.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local ="clr-namespace:WpfTests" Title="MainWindow" Height="350" Width="525"> <Window.Style> <Style> <!--<Setter Property="Canvas.Background" Value="Gray"/>--> <Style.Triggers> <Trigger...

When dependency property is being applied?

c#,wpf,xaml,dependency-properties
I'm doing some training project right now. It's supposed to convert numbers into different strings. Heres the converted Control, and in the bottom way I use it in my Main Window. So the first problem is that I want to create instance of converter based on value I pass to...