dependency-properties

How do I make Binding respect DependencyProperty value coercion?

无人久伴 提交于 2019-12-06 19:21:12
问题 I have a control with a DependencyProperty with a CoerceValueCallback. This property is bound to a property on a model object. When setting the control property to a value that causes coercion the Binding pushes the uncoerced value to the model object. The property value on the control is coerced correctly. How do I get the Binding to push the coerced value to the model object? void Initialize() { UIObject ui = new UIObject(); ModelObject m = new ModelObject(); m.P = 4; Binding b = new

UWP ValueConverter with DependencyProperty

三世轮回 提交于 2019-12-06 16:45:15
I have a UWP project, and I am trying to get a binding on my ValueConverter . It is based on this guide . I have created a DependencyProperty on the ValueConverter , but it is always null , instead of an element of type Vehicle . There is my code: MainPage.xaml <Page x:Class="Project.Pages.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:conv="using:Project

Binding UserControl inside a ListView datatemplate WPF

蹲街弑〆低调 提交于 2019-12-06 14:12:47
So i have this issue: I have created a UserControl (basically a textbox and label). This user control I am able to Bind using a Dependency Property. I have a ListView in which I can put a textbox in the datatemplate and bind the "text" property to the binded value. so far so good. but now if I try to put the UserControl into that very same scenario the DependencyProperty stops working. Here is the code: [ListView] <ListView x:Name="DtContactDetailListView" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <UserControl:tbx label="{Binding detail}" text="{Binding value}"/> <

Default value for the 'Options' property cannot be bound to a specific thread

匆匆过客 提交于 2019-12-06 12:02:27
I find that when I change a class from public class MarkdownEditorOptions : ObservableObject to public class MarkdownEditorOptions : INotifyPropertyChanged, DependencyObject as I wanted to use dependency properties, I get the error Default value for the 'Options' property cannot be bound to a specific thread. ...\Views\ShellView.xaml Options is declared as a dependency property on ShellViewModel public MarkdownEditorOptions Options { get { return (MarkdownEditorOptions)GetValue(OptionsProperty); } set { SetValue(OptionsProperty, value); } } public static readonly DependencyProperty

How do I bind to this custom dependency property?

末鹿安然 提交于 2019-12-06 10:17:27
I have a DependencyProperty in my custom UserControl that looks like this: public static readonly DependencyProperty ColumnWidthProperty = DependencyProperty.Register("ColumnWidth", typeof(int), typeof(CallBoard), new PropertyMetadata(150)); public int ColumnWidth { get { return (int)GetValue(ColumnWidthProperty); } set { SetValue(ColumnWidthProperty, value); } } In Expression Blend 3, I have this: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

Strange error in code converted to VB.NET from C# [duplicate]

本秂侑毒 提交于 2019-12-06 06:12:06
This question already has an answer here : Closed 7 years ago . Possible Duplicate: Method group in VB.NET? While reading an answer I got this code: public static class Helper { public static bool GetAutoScroll(DependencyObject obj) { return (bool)obj.GetValue(AutoScrollProperty); } public static void SetAutoScroll(DependencyObject obj, bool value) { obj.SetValue(AutoScrollProperty, value); } public static readonly DependencyProperty AutoScrollProperty = DependencyProperty.RegisterAttached("AutoScroll", typeof(bool), typeof(Helper), new PropertyMetadata(false, AutoScrollPropertyChanged));

Why do so many wpf controls implement CLR properties instead of dependency properties?

女生的网名这么多〃 提交于 2019-12-06 05:51:22
is it because the controls programmers are lazy, too hard to implement or not knowledgeable? Wether they are custom controls from 3rd party vendors or Microsoft itself, very much controls have often clr properties instead of DP. Result is I can not bind to them and is wpf not all about binding? :/ My next side question would be, why do so many wpf controls offer visual parts but they are not member of the visual tree ? see wpf datagrid columns, headers... What do you think? You don't provide examples of the controls you're thinking of, and even then it would be hard to peer into the

MVVM + UserControl + Dependency Property

半世苍凉 提交于 2019-12-06 02:47:23
问题 Alright, this is somewhat related to this question: WPF Printing multiple pages from a single View Model I tried to follow the advice given there but now I am stuck. My application uses a MainView.xaml and the appropriate MainViewViewModel.cs, I am using MVVM Light in the background. Now - according to the post - it seems I have to do the following: Create a user control Expose some properties from the user control Make sure the view model shows these properties The idea is clear but I am

Dependency property error

谁说胖子不能爱 提交于 2019-12-05 22:59:10
问题 I am learning dependency properties. I read many posts & books but still I am not clear. The program shown below is which I wrote to learn. Some error in that, please help in resolving. I have questions. The main use of custom Dependency property element is for the notification of change? I found an 'IsDefaultProperty' code for Button in a WPF text book. It means ' IsDefault ' property is a dependency property? Why they shown that code? It means, internally, in Button class, its defined like

Change binding value, not binding itself

六眼飞鱼酱① 提交于 2019-12-05 22:00:39
问题 I've got a WPF UserControl containing a DependencyProperty (MyProperty). The DependencyProperty is bound to a Property in the DataContext. Now in the UserControl I want to change the value of the bound property. But if I assign MyProperty = NewValue the Binding is lost and replaced by NewValue. What I want to achieve is change the DataContext-property the DependencyProperty is bound to. How do I achieve this instead of changing the binding? To clarify: using something like MyTextBox.Text = "0