dependency-properties

Unity Static Property Injection

我们两清 提交于 2019-12-12 10:48:50
问题 I have two classes, one which sets up the container by registering types and one which contains a static property which I want to inject into. My issue is the property is never set by injection so when I call a method on it, the property is always null. public class ClassOne { public void Method() { Container.RegisterType<IClass, ClassImplOne>("ImplOne"); Container.RegisterType<IClass, ClassImplTwo>("ImplTwo"); } } public static class ClassTwo { [Dependency] public static IClass SomeProperty

WPF Custom Control, DependencyProperty issue

妖精的绣舞 提交于 2019-12-12 09:23:29
问题 Ive got a test code setup with the custom control: /// <summary> /// Interaction logic for UCTest.xaml /// </summary> public partial class UCTest : UserControl { public static readonly DependencyProperty LastNameProperty = DependencyProperty.Register("LastName", typeof(string), typeof(UCTest), new PropertyMetadata("No Name", LastNameChangedCallback, LastNameCoerceCallback), LastNameValidateCallback); private static void LastNameChangedCallback( DependencyObject obj,

Base class DependencyProperty value change in WPF

时光总嘲笑我的痴心妄想 提交于 2019-12-12 08:57:11
问题 I have a DependencyProperty in the ClassA. I derived another ClassB from ClassA. When the value of this property is updated or changed in ClassA, How it can be notified or reflected in the derived ClassB with out adding any additional code in ClassA ? 回答1: By registering a PropertyChangedCallback for ClassB through DependencyProperty.OverrideMetadata in the derived class: class ClassB { static ClassB() { ClassA.SomeValueProperty.OverrideMetadata( typeof(ClassB), new PropertyMetadata

Setting up binding to a custom DependencyProperty inside a WPF user control

隐身守侯 提交于 2019-12-12 07:56:08
问题 I have a WPF UserControl containing a custom DependencyProperty named MyDP. I want to bind this to a property on my ViewModel (which is injected as the UserControl's DataContext). I know one way to do it by setting the binding in the UserControl's declaration in the parent window's XAML as such: <Window x:Class="MyNamespace.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:views="clr-namespace

WPF - Compilation error: Tags of type 'PropertyArrayStart' are not supported in template sections

瘦欲@ 提交于 2019-12-12 07:40:07
问题 Ordinarily I wouldn't just post an error message on SO, but after a Google search only found one hit, I thought I'd at least open the floor for this error here on SO. I have a custom control called Sparkline with a dependency property called Values of type unit[] . Here's an example where I use it in a DataTemplate : <DataTemplate DataType="{x:Type Activity:ActivityHistory}"> <Controls:Sparkline Grid.Column="1" Values="{Binding Path=Values}" /> </DataTemplate> This code doesn't compile. I

Update binding without DependencyProperty

冷暖自知 提交于 2019-12-12 06:03:51
问题 I have a lot of existing business objects with many properties and collections inside which I want to bind the userinterface to. Using DependencyProperty or ObservableCollections inside these objects is not an option. As I know exactly when I modify these objects, I would like to have a mechanism to update all UI controls when I do this. As an extra I also don't know which UI controls bind to these objects and to what properties. Here is a simplified code of what I tried to do by now: public

WPF seemingly super-simple dependency property

北城余情 提交于 2019-12-12 05:13:27
问题 I'm puzzled. I'm trying to create a user control called TranslationView . It consists pretty much entirely of a single ListView . I don't think that's important now however, because I cannot even compile my code-behind. This is the code-behind for the user control: namespace Subster { /// <summary> /// Interaction logic for TranslationView.xaml /// </summary> public partial class TranslationView : UserControl { // Generated using "propdp" in Visual Studio 2008. public ObservableCollection

Sharing dependency property in C# (WPF) between two classes

送分小仙女□ 提交于 2019-12-12 04:40:09
问题 I want two share a DepedencyProperty between to classes using AddOwner (any other approach is welcome), e.g. class ClassA : DependencyObject { public int Number { get { return (int)GetValue(NumberProperty); } set { SetValue(NumberProperty, value); } } public static readonly DependencyProperty NumberProperty = DependencyProperty.Register("Number", typeof(int), typeof(ClassA), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.Inherits)); } and class ClassB : DependencyObject {

WPF: Can't binding to Dependency Property in User Control

余生颓废 提交于 2019-12-12 03:34:34
问题 Why I can't bind to the Dependency Property in my UserControl? I only see the String "Test" as the default value but the binding does not run in a test application. if i do the same binding in the test application in a textblock object than it works. so the problem must be in the myItem class with the dependencyproperty. Code: public partial class myItem : UserControl, INotifyPropertyChanged { public static DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof

bind a value having dependency property from one class to another class textbox control in wpf

六月ゝ 毕业季﹏ 提交于 2019-12-12 03:29:35
问题 I have two classes Radial.xaml.cs and ToothDimension.xaml.cs, want to bind value of the class Radial.xaml.cs textbox control to the dependency property of another class ToothDimension.xaml.cs which works fine. It's not getting bound to text box control. Do I need to change DataContext in Radial.xaml.cs? I tried this: Radial.xaml.cs public Radial() { InitializeComponent(); DataContext = new ToothDimension(); } Radial.xaml <TextBlock x:Name="Length" Text="{Binding DataContext.ToothHeight}"