dependency-properties

Binding to a usercontrols dependencyproperties

陌路散爱 提交于 2019-12-02 16:29:24
问题 I have a WPF UserControl project named FormattedTextBox that contains a TextBox and a WPF window project in the same solution. My user control has two dependency properties registered like this: public static readonly DependencyProperty NumberProperty = DependencyProperty.Register("Number", typeof(double), typeof(FormattedTextBox), new FrameworkPropertyMetadata()); public static readonly DependencyProperty NumberFormatStringProperty = DependencyProperty.Register("NumberFormatString", typeof

Usercontrol using wrong Datacontext

谁说胖子不能爱 提交于 2019-12-02 15:21:51
问题 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

Routed events and dependency properties .NET wrapper confusion

时光总嘲笑我的痴心妄想 提交于 2019-12-02 13:50:17
问题 I'm new to WPF and have a confusion about wrapping syntax of routed events and dependency properties I've seen on many sources that routed events and dependency properties are wrapped like this // Routed Event public event RoutedEventHandler Click { add { base.AddHandler(ButtonBase.ClickEvent, value); } remove { base.RemoveHandler(ButtonBase.ClickEvent, value); } } // Dependency Property public Thickness Margin { set { SetValue(MarginProperty, value); } get { return (Thickness)GetValue

how to bind collection to custom control in wpf

倾然丶 夕夏残阳落幕 提交于 2019-12-02 12:39:54
问题 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

Implementing a pause in WPF

北城余情 提交于 2019-12-02 10:37:20
问题 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"

Cannot bind DependencyProperty of type IList from both XAML and Setter

大憨熊 提交于 2019-12-02 09:47:12
After implementing the propsed code from here: Cannot bind ObservableCollection to List dp from xaml I found out that if I had several instances of the control in the same page, the IList recieved all the values given to all the controls. I read online that in order to solve this, one must write: SetValue(...) in the constructor. This causes the Setter that is shown in above link not to work. (I guess that is because this time we need the IList to be static and not per-instance). Please help! Thanks Use SetCurrentValue instead of SetValue. 来源: https://stackoverflow.com/questions/17007491

Binding to a usercontrols dependencyproperties

坚强是说给别人听的谎言 提交于 2019-12-02 09:42:17
I have a WPF UserControl project named FormattedTextBox that contains a TextBox and a WPF window project in the same solution. My user control has two dependency properties registered like this: public static readonly DependencyProperty NumberProperty = DependencyProperty.Register("Number", typeof(double), typeof(FormattedTextBox), new FrameworkPropertyMetadata()); public static readonly DependencyProperty NumberFormatStringProperty = DependencyProperty.Register("NumberFormatString", typeof(string), typeof(FormattedTextBox), new FrameworkPropertyMetadata()); I make an instance of my

How can I set the text of a label

血红的双手。 提交于 2019-12-02 08:50:19
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:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" DataContext="{Binding RelativeSource=

Image.Height TemplateBinding does not work

余生颓废 提交于 2019-12-02 07:14:58
I have created a CustomControl implemented from Button class in WPF. public class ImageButton : Button { ... public int ImageHeight { get { return (int)GetValue(ImageHeightProperty); } set { SetValue(ImageHeightProperty, value); } } public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(int), typeof(ImageButton), new UIPropertyMetadata(32)); ... } And I have resource template like this: <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type custom:ImageButton}"> <Border> <StackPanel> <Image Name="image" Height

Custom Control DataBinding wpf

淺唱寂寞╮ 提交于 2019-12-02 05:54:08
问题 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(