Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update multiple instances of user control using MVVM databinding WPF?
    primarykey
    data
    text
    <p>I have created a <code>UserControl</code> with a <code>ProgressBar</code> and a <code>Label</code>. </p> <pre><code>&lt;Label Content="{Binding ElementName=UserControl, Path=StatusProperty}" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="76,0,0,32" Name="lblStatus" VerticalAlignment="Bottom" Grid.RowSpan="2" /&gt; &lt;ProgressBar Grid.Row="2" Height="20" HorizontalAlignment="Left" Margin="12,3,0,0" Name="pbCheckProgress" Style="{DynamicResource ProgressBarStyle}" Maximum="{Binding ElementName=UserControl, Path=MaximumProperty}" Minimum="{Binding ElementName=UserControl, Path=MinimumProperty}" Value="{Binding ElementName=UserControl, Path=ValueProperty}" VerticalAlignment="Top" Width="156" /&gt; </code></pre> <p>Then I have created the following <code>DependencyProperties</code>:</p> <pre><code>// Dependency Properties for labels public static readonly DependencyProperty StatusProperty = DependencyProperty.Register("Status", typeof(string), typeof(UserControl1), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); // Dependency Properties for progress bar properties public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), typeof(UserControl1), new FrameworkPropertyMetadata(0.0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(UserControl1), new FrameworkPropertyMetadata(0.0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(UserControl1), new FrameworkPropertyMetadata(0.0d, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); </code></pre> <p>Now I would like to create multiple instances of this <code>UserControl</code> in the same page and update the <code>ProgressBar</code> from code behind using MVVM. But I could not figure this out. Do I need to have a ViewModel for the <code>UserControl</code> so that every instance will have its own copy of ViewModel.</p> <p>Is there a way to update all the instances from the page ViewModel?</p> <p>Thanks &amp; Regards, Bharat</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.
 

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