dependency-properties

how to bind collection to custom control in wpf

风格不统一 提交于 2019-12-02 04:19:32
I am building a custom control and I want to pass a collection to it so that control display that collection, my code is as the following : <gm:Calendar SubscriptionSource="{Binding Subscriptions}"></gm:Calendar> and in Custom control "Calendar" public static readonly DependencyProperty SubscriptionSourceProperty = DependencyProperty.Register( "SubscriptionSource", typeof(ObservableCollection<Subscription>), typeof(Calendar), new FrameworkPropertyMetadata(new ObservableCollection<Subscription>())); public ObservableCollection<Subscription> SubscriptionSource { get { return

Usercontrol using wrong Datacontext

筅森魡賤 提交于 2019-12-02 03:17:53
I have a UserControl that is used in a parent control in this way: <Views:TranslationTextInput Translation="{Binding SelectedEntity.Name}"/> The parent control DataContext is a ViewModel containing the SelectedEntity Property. In my child UserControl I define a new ViewModel as the DataContext: <UserControl.DataContext> <vm:TranslationTextInputViewModel x:Name="vm"></vm:TranslationTextInputViewModel> </UserControl.DataContext> In the code behind I have: public static readonly DependencyProperty TranslationProperty = DependencyProperty.Register("Translation", typeof(Translation),typeof

Implementing a pause in WPF

不羁的心 提交于 2019-12-02 03:15:56
Here you have a simple WPF program: <!-- Updater.xaml --> <Window x:Class="Update.Updater" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}"> <Grid> <StackPanel> <Button Click="Button_Click" Height="50"></Button> <Label Content="{Binding Label1Text}" Height="50"></Label> <Label Content="{Binding Label2Text}" Height="50"></Label> </StackPanel> </Grid> </Window> // Updater.xaml.cs using System.Threading; using System

Allow only OneWayToSource binding mode

百般思念 提交于 2019-12-02 02:19:58
I have EntitiesUserControl responsible for EntitiesCount dependency property: public static readonly DependencyProperty EntitiesCountProperty = DependencyProperty.Register( nameof(EntitiesCount), typeof(int), typeof(EntitiesUserControl), new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public int EntitiesCount { get { return (int)this.GetValue(EntitiesCountProperty); } set { this.SetValue(EntitiesCountProperty, value); } } Another (primary) control include EntitiesUserControl and read it property through binding: <controls:EntitiesUserControl

Custom Control DataBinding wpf

痴心易碎 提交于 2019-12-02 01:27:27
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 MyProperty is defined as: public static readonly DependencyProperty MyValueProperty = DependencyProperty.Register("MyValue", typeof(double), typeof(CustomOEE), new FrameworkPropertyMetadata((Double)20

Dependency property binding usercontrol with a viewmodel

纵然是瞬间 提交于 2019-12-02 00:32:39
问题 Essentially, I have a main window with a user control on it containing a property which is bound to the view model of the main window. The idea is that when the property changes in the user form that by the binding the property in the main window viewmodel will also change. The problem is that this works when the user control has no ViewModel, when I add a simple ViewModel to the user control, the binding no longer works. And as I need to have a ViewModel for my control I need to work out why

Register Property as DependencyProperty

感情迁移 提交于 2019-12-01 20:53:57
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 ChartEntries="{Binding ChartEntriesSource}"/> I get a message in the xaml-window that I can not bind to a

WinRT DependencyProperty with IEnumerable not firing at all

懵懂的女人 提交于 2019-12-01 17:59:53
I've scoured and scoured since I know there has been a lot posted about Dependency Properties but I just haven't quite seen anything out there that has a solution that works. I'm trying to bind an ObservableCollection from my ViewModel to my AutoCompleteBox. My ViewModel is returning the data, the Getter is being hit. However, after that, the control's SetValue or OnItemsSourcePropertyChanged doesn't fire. Any thoughts as to what might be wrong? I've got a control like so: [ContentProperty(Name = "ItemsSource")] public partial class AutoCompleteBox : Control { //local stuff private ListBox lb;

WinRT DependencyProperty with IEnumerable not firing at all

本秂侑毒 提交于 2019-12-01 17:44:24
问题 I've scoured and scoured since I know there has been a lot posted about Dependency Properties but I just haven't quite seen anything out there that has a solution that works. I'm trying to bind an ObservableCollection from my ViewModel to my AutoCompleteBox. My ViewModel is returning the data, the Getter is being hit. However, after that, the control's SetValue or OnItemsSourcePropertyChanged doesn't fire. Any thoughts as to what might be wrong? I've got a control like so: [ContentProperty

How to use PropertyChangedCallBack

。_饼干妹妹 提交于 2019-12-01 14:59:21
I have a TextBox Binded to a dependancy property, I have implemented a PropertyChangedCallBack function, when the text changes I need to call textbox.ScrollToEnd() but I cant since the PropertChanged function need to be static, is there a way around this? static FrameworkPropertyMetadata propertyMetaData = new FrameworkPropertyMetadata("MyWindow", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(TextProperty_PropertyChanged)); public static readonly DependencyProperty TextProperty = DependencyProperty.Register("TextProperty", typeof(string), typeof(OutputPanel