dependency-properties

Handling a UserControl's DependencyProperty Command

久未见 提交于 2019-12-01 13:39:07
I am struggling with getting a WPF UserControl to update one of its DependencyProperty when a DependencyProperty Command is invoked. Here's a an example that can hopefully demonstrate what I am trying to achieve. Basically it's a user control with a button on it. When the button is clicked, I'd like to increment an integer ( MyValue ) using a command ( MyCommand ): User Control <UserControl x:Class="UserControl1" x:Name="root" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org

Bind to wpf custom control dependency property for tooltip?

感情迁移 提交于 2019-12-01 13:17:01
I have a custom control I wrote in WPF, which has a Boolean dependency property: public static readonly DependencyProperty IsAlertProperty = DependencyProperty.Register("IsAlert", typeof(bool), typeof(AlertControl), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.None, OnIsAlertChanged, null, false, UpdateSourceTrigger.PropertyChanged)); public bool IsAlert { get { return (bool)GetValue(IsAlertProperty); } set { SetValue(IsAlertProperty, value); } } In my Generic.xaml, I have the following xaml code: <Style TargetType="{x:Type local:AlertControl}"> <Setter

Is there a notification mechanism for when a dependency property has changed?

拈花ヽ惹草 提交于 2019-12-01 11:14:35
In a Silverlight application I'm trying to find out when a property on a usercontrol has changed. I'm interested in one particular DependencyProperty, but unfortunately the control itself doesn't implement INotifyPropertyChanged. Is there any other way of determining if the value has changed? In WPF you have DependencyPropertyDescriptor.AddValueChanged , but unfortunately in Silverlight there's no such thing. So the answer is no. Maybe if you explain what are you trying to do you can workaround the situation, or use bindings. You can. Atleast I did. Still need to see the pros and Cons. ///

Bind to wpf custom control dependency property for tooltip?

二次信任 提交于 2019-12-01 10:57:14
问题 I have a custom control I wrote in WPF, which has a Boolean dependency property: public static readonly DependencyProperty IsAlertProperty = DependencyProperty.Register("IsAlert", typeof(bool), typeof(AlertControl), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.None, OnIsAlertChanged, null, false, UpdateSourceTrigger.PropertyChanged)); public bool IsAlert { get { return (bool)GetValue(IsAlertProperty); } set { SetValue(IsAlertProperty, value); } } In my Generic

Handling a UserControl's DependencyProperty Command

旧巷老猫 提交于 2019-12-01 10:57:09
问题 I am struggling with getting a WPF UserControl to update one of its DependencyProperty when a DependencyProperty Command is invoked. Here's a an example that can hopefully demonstrate what I am trying to achieve. Basically it's a user control with a button on it. When the button is clicked, I'd like to increment an integer ( MyValue ) using a command ( MyCommand ): User Control <UserControl x:Class="UserControl1" x:Name="root" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Is there a notification mechanism for when a dependency property has changed?

。_饼干妹妹 提交于 2019-12-01 09:15:18
问题 In a Silverlight application I'm trying to find out when a property on a usercontrol has changed. I'm interested in one particular DependencyProperty, but unfortunately the control itself doesn't implement INotifyPropertyChanged. Is there any other way of determining if the value has changed? 回答1: In WPF you have DependencyPropertyDescriptor.AddValueChanged, but unfortunately in Silverlight there's no such thing. So the answer is no. Maybe if you explain what are you trying to do you can

Why declare DependencyProperty members public not protected?

半腔热情 提交于 2019-12-01 07:48:08
Why create DependencyProperty member in this way: public static readonly DependencyProperty DepProperty = DependencyProperty.Register(...); and not in that way: protected static readonly DependencyProperty DepProp = DependencyProperty.Register(...); Why do we need to use the DevProp member from outside when we have the CLR "wrappers": public bool Dep { get { return (bool)GetValue(DepProperty); } set { SetValue(DepProperty, value); } } According to MSDN , restrictive access modifiers don't actually provide the intended access protection from certain APIs, so there's no point declaring

Trying to change a CroppedBitmap's SourceRect at runtime

谁说胖子不能爱 提交于 2019-12-01 06:28:05
问题 When I try to change a CroppedBitmap's SourceRect property at runtime, nothing happens. There's no error, and the property value doesn't actually get changed. I'm trying to do sprite animation. I have a BitmapSource that contains a spritesheet, which is a single bitmap containing a grid of different poses for the sprite. Then I have a CroppedBitmap that has the spritesheet as its Source, and a SourceRect that pulls one of the poses out of the spritesheet. At runtime, when I want to animate, I

If we can't bind a MouseBinding's Command, what are we supposed to do?

∥☆過路亽.° 提交于 2019-12-01 05:58:28
I would love to be able to use a regular MouseBinding to capture a CTRL-Click event on my TextBlock . Unfortunately the Command property is not a dependency property and I'm using MVVM, so I can't bind it to my viewmodel. How could Microsoft have left out this basic functionality? Are there no easy ways to detect CTRL-Clicks and bind them to a command in my viewmodel? You could always take a look at using Attached Command Behaviours . Originally I believe I was referring to the use of TextBlock 's InputBindings member. In .NET 4 InputsBinding s now inherit from Freezable , so now the Command

Why declare DependencyProperty members public not protected?

守給你的承諾、 提交于 2019-12-01 05:33:54
问题 Why create DependencyProperty member in this way: public static readonly DependencyProperty DepProperty = DependencyProperty.Register(...); and not in that way: protected static readonly DependencyProperty DepProp = DependencyProperty.Register(...); Why do we need to use the DevProp member from outside when we have the CLR "wrappers": public bool Dep { get { return (bool)GetValue(DepProperty); } set { SetValue(DepProperty, value); } } 回答1: According to MSDN, restrictive access modifiers don't