dependency-properties

DependencyProperty value not getting set through data binding

不羁的心 提交于 2020-01-02 05:38:08
问题 I have a class which has a DependencyProperty member: public class SomeClass : FrameworkElement { public static readonly DependencyProperty SomeValueProperty = DependencyProperty.Register( "SomeValue", typeof(int), typeof(SomeClass)); new PropertyMetadata( new PropertyChangedCallback(OnSomeValuePropertyChanged))); public int SomeValue { get { return (int)GetValue(SomeValueProperty); } set { SetValue(SomeValueProperty, value); } } public int GetSomeValue() { // This is just a contrived example

DependencyProperty of type “Binding” is not being updated

流过昼夜 提交于 2020-01-01 12:08:49
问题 I'm having trouble creating a DependencyProperty of type "Binding". Other types work ok, and they resolve successfully if I populate them using a binding. In my scenario I want to grab the raw binding, so that I can use it to bind to properties of child objects, in much the same way that DataGrid does columns - ie for each binding specified in a column, it binds to each of the items in the ItemsSource collection, rather than binding the the DataContext itself. <mg:MultiSelectDataGrid x:Name=

DependencyProperty Registration in ViewModel

守給你的承諾、 提交于 2020-01-01 11:55:55
问题 I am finding a lot of discussions about ViewModels and their Properties that compare two approches: implementation of INotifyPropertyChanged or implementation via Dependency Properties . While I am doing INotifyPropertyChanged a lot (and it's working) I am having difficulties implementing the DP-approach. When I am registering the DP in the ViewModel like this public static readonly DependencyProperty SomePropertyProperty = DependencyProperty.Register("SomeProperty", typeof(string), typeof

How Dependency Property tell the object to apply to?

我与影子孤独终老i 提交于 2020-01-01 10:12:28
问题 (I am totally new to this concept so I may be asking very basic questions.) A dependency property is registered with the code below: public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata); Logically, it did nothing but associate a property name with the owner type. So if I have multiple instances of the owner type, and each instance set the DP to different values. How could these values be stored? Update 1 - 10:04 AM 10/30/2013

Displaying FontFamily in Combobox

…衆ロ難τιáo~ 提交于 2020-01-01 09:50:12
问题 My goal is to manipulate the text-styles of my application via DependencyProperties. I got a diagram in which the texts are to be manipulated in size, fontfamily, color, etc. So I'd like to use an interface similar to a rich text editor like Word. I'm using this code in my TextStyleVM http://shevaspace.blogspot.com/2006/12/i-have-some-fun-with-formattedtext_14.html So I have a FontFamilyProperty and a Getter and Setter for it: public static DependencyProperty FontFamilyProperty =

Binding to UserControl DependencyProperty

≯℡__Kan透↙ 提交于 2020-01-01 02:17:08
问题 I have created a UserControl with some DependencyProperties (in the example here only one string property). When I instantiate the Usercontrol, I can set the property of the UserControl and it is shown as expected. When I am trying to replace the static text by Binding, nothing is displayed. My UserControl looks as follows: <User Control x:Class="TestUserControBinding.MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx

UserControl DependencyProperty binding in ListView

戏子无情 提交于 2019-12-29 09:22:16
问题 When I try to use a custom UserControl in a ListView, it fails and only empty blocks are displayed (the following TextBlock works though). While the customControl outside the ListView works pretty well. What's the problem? MainWindow.xaml <Grid> <StackPanel> <controls:CustomControl x:Name="customControl" CustomText="Test"/> <ListView x:Name="listView"> <ListView.ItemTemplate> <DataTemplate> <StackPanel> <controls:CustomControl CustomObject="{Binding}"/> <TextBlock Text="{Binding Text}"/> <

Data binding dependency property to data object

拜拜、爱过 提交于 2019-12-29 08:56:12
问题 I have a DependencyObject with a DependencyProperty: public class DependencyObjectClass: DependencyObject { public static DependencyProperty BooleanValueProperty = DependencyProperty.Register("BooleanValue", typeof (bool), typeof (DependencyObjectClass)); public bool BooleanValue { get { return (bool)GetValue(BooleanValueProperty); } set { SetValue(BooleanValueProperty, value); } } } I also have my data source class: public class DataSource: INotifyPropertyChanged { private bool _istrue;

Why dependency properties in WPF has to be Static

夙愿已清 提交于 2019-12-29 03:28:06
问题 Why a dependency property has to be Static? I have seen that it has been already asked in some post here, but I am not able to understand it properly. It will be great if someone can help me understand with a small snippet too. 回答1: The magic here is, the declaration of DependencyProperty is static not its value (i.e the memory storage). The declaration that you add with static keyword is just the identifier(key) of the DependencyProperty for a particular DependencyObject . As same identifier

Simple Dependency Property and UserControl issues in C#

ぃ、小莉子 提交于 2019-12-29 01:44:13
问题 My end goal is to expose the Text value of a TextBox that I have in a UserControl , from the UserControl 's call in XAML. <my:UserControl SetCustomText="Blah blah this is variable"> would render the UserControl with that TextBox 's text filed in. I've been working at it using various examples but I always end up with "The Property SetCustomText was not found in type UserControl" 回答1: Example of how you can do this: <UserControl x:Class="Test.UserControls.MyUserControl1" xmlns="http://schemas