Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know what is the best solution for you. One of these ,however, would be that you use Property like:</p> <pre><code> //field private int _dependOne; //property public int DependOne { get { return _dependOne; } set { _dependOne = value; Count += value; } } //Finally, use the property instead of the field //dependOne = dependOne + 2; DependOne += 2; </code></pre> <hr> <p><strong>UPDATED:</strong> The important thing is that you don't update ViewModel properties in Codebehind. Instead, you could call a ViewModel method.</p> <p><strong>XAML</strong></p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Local="clr-namespace:WpfApplication1" Title="MainWindow" Height="350" Width="525"&gt; &lt;StackPanel&gt; &lt;StackPanel.Resources&gt; &lt;Local:MyConverter x:Key="myConverter"/&gt; &lt;/StackPanel.Resources&gt; &lt;TextBox&gt; &lt;TextBox.Text&gt; &lt;MultiBinding Converter="{StaticResource myConverter}"&gt; &lt;Binding Path="DependOne" Mode="OneWay"/&gt; &lt;Binding Path="DependTwo" Mode="OneWay"/&gt; &lt;/MultiBinding&gt; &lt;/TextBox.Text&gt; &lt;/TextBox&gt; &lt;Button Click="button1_Click"&gt;click&lt;/Button&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p><strong>CODE</strong></p> <pre><code>public partial class MainWindow : Window { ViewModel vm; public MainWindow() { InitializeComponent(); vm = new ViewModel(); this.DataContext = vm; } //public int Count //{ // get { return (int)GetValue(CountProperty); } // set { SetValue(CountProperty, value); } //} //// Using a DependencyProperty as the backing store for Count. This enables animation, styling, binding, etc... //public static readonly DependencyProperty CountProperty = // DependencyProperty.Register("Count", typeof(int), typeof(MainWindow), new UIPropertyMetadata(12)); private void button1_Click(object sender, RoutedEventArgs e) { vm.UpdateCount(); } } public class ViewModel : INotifyPropertyChanged { public ViewModel() { } private int dependOne = 0; public int DependOne { get { return dependOne; } set { dependOne = value; OnPropertyChanged("DependOne"); } } private int dependTwo = 0; public int DependTwo { get { return dependTwo; } set { dependTwo = value; OnPropertyChanged("DependTwo"); } } #region -- INotifyPropertyChanged Members -- public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyNameArg) { PropertyChangedEventHandler handler = this.PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyNameArg)); } } #endregion internal void UpdateCount() { DependOne = 3; DependTwo = 4; } } public class MyConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var dependOne = (int)values[0]; var dependTwo = (int)values[1]; return (dependOne + dependTwo).ToString(); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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