dependency-properties

Displaying FontFamily in Combobox

≡放荡痞女 提交于 2019-12-04 06:28:05
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 = DependencyProperty.Register( "FontFamily", typeof(FontFamily), typeof(OutlinedText), new FrameworkPropertyMetadata(

How can I set the text of a label

徘徊边缘 提交于 2019-12-04 06:01:54
问题 I've got a usercontrol that I want to put in a FixedDocument, but before I do that I need to change the text of a label. I think I need to use Dependency Properties. Here's the simplified XAML. <UserControl x:Class="PrinterTest.TestControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc

UserControl Dependency Property design time

旧城冷巷雨未停 提交于 2019-12-04 04:48:05
I'm creating a simple User Control in WPF that contains a TextBlock inside a Button. <UserControl x:Class="WpfExpansion.MyButton"..... > <Grid > <Button Background="Transparent" > <TextBlock Text="{Binding Path=Text}"/> </Button> </Grid> </UserControl> And also the "Text" dependency property. public partial class MyButton : UserControl { public MyButton() { InitializeComponent(); this.DataContext = this; } public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public static readonly DependencyProperty TextProperty = DependencyProperty

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

大城市里の小女人 提交于 2019-12-04 04:27:28
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 being called. I modify the get;Set up to a point now they look like this: get{return null;} set{} And it is

Missing snippet in visual studio

老子叫甜甜 提交于 2019-12-04 03:48:07
Same installation of Visual studio on two machines, but in 1 i cant find the snippet "propdp" for DependencyProperty ? I only have prop/propg, cant really understand why. Is there an addon i have to install? Came across this same issue myself today after a fresh install of VS2008 on Win7 64 All I had to do to fix it was to Go to Tools > Code Snippets Manager Select Visual C# from the drop down menu Click Add Select the NetFx30 directory containing the code snippets, in my case it was... C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC#\Snippets\1033\NetFX30 You should immediately be able

Change binding value, not binding itself

可紊 提交于 2019-12-04 03:14:37
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"; I'll release the binding. How would I set Text, leave the binding intact so the property Text is

Spring bean fields injection

六月ゝ 毕业季﹏ 提交于 2019-12-04 02:19:38
Using Spring IoC allows to set bean properties exposed via setters: public class Bean { private String value; public void setValue(String value) { this.value = value; } } And the bean definition is: <bean class="Bean"> <property name="value" value="Hello!"> </bean> Is there any existing plugins/classes for Spring Framework that allows to directly expose bean fields as properties without defining setters? Something like this with the same bean definition: public class Bean { @Property private String value; } You can: use the @Value annotation and inject a property (using expression language)

Why Dependency property are declared as static readonly?

孤者浪人 提交于 2019-12-04 01:58:36
It is clear to me why dependency property are static and the question still remain on my mind is why we need to use Readonly keyword at the time of declaration of Dependency Property. Conceptually a dependency property is something that a dependency object simply has and that does not depend on when you use the property. Just like a CLR property, if you ask does this object have a Total property, you know it cannot be a double now but an int later. As a result, we'd make the dependency property const if we could, but we cannot, so readonly is the next best thing. Using the readonly keyword has

Order that DependencyProperties bindings are evaluated?

让人想犯罪 __ 提交于 2019-12-04 01:21:37
What determines the order that multiple DepdencyProperties on the same control get evaluated in? I am using the Extended WPF Toolkit PropertyGrid and have both SelectedObject and PropertyDefinitions bound: <extToolkit:PropertyGrid AutoGenerateProperties="False" SelectedObject="{Binding ActiveDataPoint}" PropertyDefinitions="{Binding ActiveDataPoint.Properties}"> The problem is that the OnSelectedObjectChanged fires from the dependency property, and in that changed handler it is referencing PropertyDefinitions, which it is seeing as null. If I comment out the OnSelectedObjectChanged handler

How to subscribe to change DependencyProperty? [duplicate]

送分小仙女□ 提交于 2019-12-03 23:55:41
Possible Duplicate: Listen to changes of dependency property Excuse me for my English. I need to create a class that could subscribe to change DependencyProperty, and depending on the new value of this property to perform some action. Like this: MyClass obj = new MyClass(); obj.Subscribe(TextBox.TextProperty, myTextBox); How can I do this? Here is one way of doing it, using the handy DependencyPropertyDescriptor class. var pd = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty, typeof(TextBox)); pd.AddValueChanged(myTextBox, OnTextChanged); private void OnTextChanged(object sender