Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding is not updated as expected
    primarykey
    data
    text
    <p>I'm building a simple <strong>UserControl</strong>, <strong>DoubleDatePicker</strong>, which defines a <strong>DependencyProperty</strong>, <strong>SelectedDate</strong> :</p> <p><strong>DoubleDatePicker.xaml</strong> :</p> <pre><code>&lt;UserControl x:Class="TestWpfDoubleDatePicker.DoubleDatePicker" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"&gt; &lt;StackPanel x:Name="LayoutRoot" Background="White"&gt; &lt;toolkit:DatePicker x:Name="DateInput" SelectedDate="{Binding SelectedDate,Mode=TwoWay}" Margin="5,0,5,0" /&gt; &lt;TextBlock Text="{Binding SelectedDate}" /&gt; &lt;toolkit:DatePicker SelectedDate="{Binding SelectedDate,Mode=TwoWay}" Margin="5,0,5,0" /&gt; &lt;/StackPanel&gt; </code></pre> <p></p> <p><strong>DoubleDatePicker.xaml.cs</strong> :</p> <pre><code>using System; using System.Windows; using System.Windows.Controls; namespace TestWpfDoubleDatePicker { public partial class DoubleDatePicker : UserControl { public static readonly DependencyProperty SelectedDateProperty = DependencyProperty.Register("SelectedDate", typeof(DateTime), typeof(DoubleDatePicker), null); public DateTime SelectedDate { get { return (DateTime)this.GetValue(SelectedDateProperty); } set { this.SetValue(SelectedDateProperty, value); } } public DoubleDatePicker() { this.InitializeComponent(); this.DataContext = this; } } } </code></pre> <p>I'd like to be able to bind the <strong>SelectedDate</strong> property from the outside but things do not seem so simple. Here is a sample code that is trying to get the value of the property in a <strong>TextBlock</strong> :</p> <p><strong>MainWindow.xaml</strong> :</p> <pre><code>&lt;Window x:Class="TestWpfDoubleDatePicker.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestWpfDoubleDatePicker" Title="MainWindow" Height="350" Width="525"&gt; &lt;StackPanel x:Name="LayoutRoot" Background="White"&gt; &lt;local:DoubleDatePicker x:Name="ddp" SelectedDate="{Binding SelectedDate}" /&gt; &lt;Button Content="Update" Click="Button_Click" /&gt; &lt;TextBlock Text="{Binding SelectedDate}" /&gt; &lt;/StackPanel&gt; </code></pre> <p></p> <p>and <strong>MainWindow.xaml.cs</strong> :</p> <pre><code>using System; using System.Windows; namespace TestWpfDoubleDatePicker { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public static readonly DependencyProperty SelectedDateProperty = DependencyProperty.Register("SelectedDate", typeof(DateTime), typeof(MainWindow), null); public DateTime SelectedDate { get { return (DateTime)this.GetValue(SelectedDateProperty); } set { this.SetValue(SelectedDateProperty, value); } } public MainWindow() { InitializeComponent(); this.DataContext = this; } private void Button_Click(object sender, RoutedEventArgs e) { this.SelectedDate = this.ddp.SelectedDate; } } } </code></pre> <p>Inside the <strong>DoubleDatePicker</strong> itself all is working fine : the <strong>SelectedDate</strong> property is updated when changed by using any of the two <strong>DatePicker</strong>, and the <strong>TextBlock</strong> of the <strong>DoubleDatePicker</strong> is updated as expected.</p> <p>But, outside, the <strong>TextBlock</strong> of the <strong>MainWindow</strong> is not updated automatically and the only way to get the <strong>SelectedDate</strong> property of the <strong>DoubleDatePicker</strong> is to get it explicitly, like it's done when clicking the <strong>Button</strong>.</p> <p><strong>What am I doing wrong ?</strong></p> <p>I'm using Visual Studio Professional 2010 with WPF 4.</p> <p>Thanks in advance for you help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload