Рассчитать значение текстового поля на основе значения выпадающего списка? (wpf) - PullRequest
0 голосов
/ 08 января 2020

У меня есть небольшая программа, потому что я новичок, моя программа заключается в том, чтобы переносить данные с sql сервер в текстовое поле с помощью опции комбобокса и использовать значение, показанное в этом текстовом поле, чтобы вычислить + я сделал это для шага Теперь я благодарю вас за помощь в вычислении значения в текстовом поле. код xaml:

<Window x:Class="comboboxapp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:comboboxapp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <local:SimpleMath x:Key="MyFriends"/>
    </Window.Resources>

    <Grid>
        <Label Content="code" HorizontalAlignment="Left" Margin="38,52,0,0" 
               VerticalAlignment="Top" Width="46" Height="23"/>
        <Label Content="pieces" HorizontalAlignment="Left" Margin="38,126,0,0" 
               VerticalAlignment="Top" Width="46" Height="23"/>
        <Label Content="layers" HorizontalAlignment="Left" Margin="38,196,0,0" 
               VerticalAlignment="Top" Width="46" Height="30"/>
        <Label Content="production pieces" HorizontalAlignment="Left" 
               Margin="0,278,0,0" VerticalAlignment="Top" Width="108" Height="25"/>
        <TextBox x:Name="txtcode" 
                 Text="{Binding Txtcode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" Margin="124,52,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtpieces" 
                 Text="{Binding Txtpieces, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" 
                 Margin="124,133,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtlayers" 
                 Text="{Binding Txtlayers,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" 
                 Margin="124,203,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtproductionpieces" 
                 Text="{Binding Txtproductionpieces,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" Margin="124,280,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <ComboBox x:Name="comboBox1" ItemsSource="{Binding Source={StaticResource MyFriends}}" 
                  HorizontalAlignment="Left" Margin="418,52,0,0" VerticalAlignment="Top" 
                  Width="319" Height="36" SelectionChanged="ComboBox1_SelectionChanged"/>
        <TextBox x:Name="txtseccond" 
                 Text="{Binding Txtseccond,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="23" 
                 Margin="124,345,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <Label Content="seccond" HorizontalAlignment="Left" Margin="38,345,0,0" 
               VerticalAlignment="Top" Width="46" Height="23"/>
        <TextBlock Text="{Binding A, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" 
                   HorizontalAlignment="Left" Margin="418,133,0,0" TextWrapping="Wrap"  
                   VerticalAlignment="Top" Height="23" Width="248"/>
        <TextBox Text="{Binding No1,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" 
                 HorizontalAlignment="Left" Height="21" Margin="426,210,0,0" 
                 TextWrapping="Wrap" VerticalAlignment="Top" Width="303"/>
    </Grid>
</Window>

C# код:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace comboboxapp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public SimpleMath Formular { get; set; }
        public object SelectedValue { get; private set; }

        public MainWindow()
        {
            Formular = new SimpleMath()
            {
                Txtcode = 0,
                Txtpieces = 0,
                Txtlayers = 0,
                Txtproductionpieces = 0,
                Txtseccond = 0,

            };
            InitializeComponent();
            DataContext = Formular;
            Fillcombobox();
        }
        private void MainWindow_Load(object sender, EventArgs e) 
        {

        }
        public void Fillcombobox()
        {
            SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial 
Catalog=LUAT;Integrated Security=True");

            string sql = " select * from comboboxnew ";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader myreader;
            try
            {
                con.Open();
                myreader = cmd.ExecuteReader();
                while (myreader.Read())
                {
                    string sname = myreader.GetInt32(0).ToString();
                    comboBox1.Items.Add(sname);

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
        public class SimpleMath : INotifyPropertyChanged
        {
            private int no1;

            public int No1
            {
                get { return no1; }
                set
                {
                    no1 = value;
                    OnPropertyChanged("No1");
                    OnPropertyChanged("A");
                }
            }
            private int txtcode;

            public int Txtcode
            {
                get { return txtcode; }
                set
                {
                    txtcode = value;
                    OnPropertyChanged("Txtcode");
                    OnPropertyChanged("A");
                }
            }
            private int txtpieces;

            public int Txtpieces
            {
                get { return txtpieces; }
                set
                {
                    txtpieces = value;
                    OnPropertyChanged("Txtcode");
                    OnPropertyChanged("A");
                }
            }
            private int txtlayers;

            public int Txtlayers
            {
                get { return txtlayers; }
                set
                {
                    txtlayers = value;
                    OnPropertyChanged("Txtlayers");
                    OnPropertyChanged("A");
                }
            }
            private int txtproductionpieces;

            public int Txtproductionpieces
            {
                get { return txtproductionpieces; }
                set
                {
                    txtproductionpieces = value;
                    OnPropertyChanged("Txtproductionpieces");
                    OnPropertyChanged("A");
                }
            }
            private int txtseccond;

            public int Txtseccond
            {
                get { return txtseccond; }
                set
                {
                    txtseccond = value;
                    OnPropertyChanged("Txtseccond");
                    OnPropertyChanged("A");
                }
            }
            public double A => No1;

            public event PropertyChangedEventHandler PropertyChanged;
            public void OnPropertyChanged([CallerMemberName()] string propertyName = null)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial 
Catalog=LUAT;Integrated Security=True");
            //  string sql = " select * from comboboxnew where code = '" + comboBox1.Text+ "';";
            string sql = " select * from comboboxnew where code = '" + comboBox1.SelectedItem + 
"';";
            //Console.WriteLine(comboBox1.Text);
            //MessageBox.Show(comboBox1.Text);
            SqlCommand cmd = new SqlCommand(sql, con); 
            SqlDataReader myreader; 
            try
            {
                con.Open();
                myreader = cmd.ExecuteReader();
                while (myreader.Read())
                {
                    string code = myreader.GetInt32(0).ToString();
                    string pieces = myreader.GetInt32(1).ToString();
                    string layers = myreader.GetInt32(2).ToString();
                    string productionpieces = myreader.GetInt32(3).ToString();
                    string seccond = myreader.GetInt32(4).ToString();
                     txtcode.Text = code;
                    //txtcode.Text =SelectedValue;
                    txtpieces.Text = pieces;
                      //txtpieces.Text = "New value";
                    txtlayers.Text = layers;
                       //txtlayers.Text = "New value";
                    txtproductionpieces.Text = productionpieces;
                     //txtproductionpieces.Text = "New value";
                    txtseccond.Text = seccond;
                    //txtseccond.Text = "New value";

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}  

enter image description here

Ответы [ 2 ]

0 голосов
/ 10 января 2020

it can caculator Показать текстовое поле sum c# код:

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace comboboxapp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
           public MainWindow()
        { 
            InitializeComponent();
            this.DataContext = new SimpleMath();
             Fillcombobox();
        }
            private void MainWindow_Load(object sender, EventArgs e)
            {

            }
            public void Fillcombobox()
            {
            SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial Catalog=LUAT;Integrated Security=True") ;

                string sql = " select * from comboboxnew ";
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataReader myreader;
                try
                {
                    con.Open();
                    myreader = cmd.ExecuteReader();
                    while (myreader.Read())
                    {
                        string sname = myreader.GetInt32(0).ToString();
                        comboBox1.Items.Add(sname);

                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }
            }
        public class SimpleMath : INotifyPropertyChanged
        {
            private int _no1;

            public int No1
            {
                get => _no1;
                set
                {
                    _no1 = value;
                    OnPropertyChanged();
                    CalculateSum();
                    OnPropertyChanged("A");
                }
            }
            private int _txtcode;

            public int Txtcode
            {
                get => _txtcode;
                set
                {
                    _txtcode = value;
                    OnPropertyChanged();
                    CalculateSum();
                    OnPropertyChanged("A");
                }
            }
            private int _txtpieces;

            public int Txtpieces
            {
                get => _txtpieces;
                set
                {
                    _txtpieces = value;
                    OnPropertyChanged();
                    CalculateSum();
                    OnPropertyChanged("A");

                }
            }
            private int _txtlayers;

            public int Txtlayers
            {
                get => _txtlayers;
                set
                {
                    _txtlayers = value;
                    OnPropertyChanged();
                    CalculateSum();
                    OnPropertyChanged("A");

                }
            }
            private int _txtproductionpieces;

            public int Txtproductionpieces
            {
                get => _txtproductionpieces;
                set
                {
                    _txtproductionpieces = value;
                    OnPropertyChanged();
                    CalculateSum();
                    OnPropertyChanged("A");

                }
            }
            private int _txtseccond;

            public int Txtseccond
            {
                get => _txtseccond;
                set
                {
                    _txtseccond = value;
                    OnPropertyChanged();
                    CalculateSum();
                    OnPropertyChanged("A");

                }
            }
            private int a;
            public int A
            {
                get => a;
                set
                {
                    a = value;
                    OnPropertyChanged();
                }
            }
            private void CalculateSum()
            {
                A = Txtcode + Txtlayers + Txtpieces;
            }
            public event PropertyChangedEventHandler PropertyChanged;
            public void OnPropertyChanged([CallerMemberName()] string propertyName = null)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {


            SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial Catalog=LUAT;Integrated Security=True");
            //  string sql = " select * from comboboxnew where code = '" + comboBox1.Text+ "';";
            string sql = " select * from comboboxnew where code = '" + comboBox1.SelectedItem + "';";

            //Console.WriteLine(comboBox1.Text);
            //MessageBox.Show(comboBox1.Text);
            SqlCommand cmd = new SqlCommand(sql, con); 
            SqlDataReader myreader; 
            try
            {

                con.Open();
                myreader = cmd.ExecuteReader();
                while (myreader.Read())
                {

                    string code = myreader.GetInt32(0).ToString();
                    string pieces = myreader.GetInt32(1).ToString();
                    string layers = myreader.GetInt32(2).ToString();
                    string productionpieces = myreader.GetInt32(3).ToString();
                    string seccond = myreader.GetInt32(4).ToString();

                    txtcode.Text = code;

                    txtpieces.Text = pieces;

                    txtlayers.Text = layers;

                    txtproductionpieces.Text = productionpieces;

                    txtseccond.Text = seccond;




            }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

    }
}  

xaml код:

    <Window x:Class="comboboxapp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:comboboxapp1"
        xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts" xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" 
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
      <Grid>
        <Label Content="code" HorizontalAlignment="Left" Margin="38,52,0,0" VerticalAlignment="Top" Width="46" Height="23"/>
        <Label Content="pieces" HorizontalAlignment="Left" Margin="38,126,0,0" VerticalAlignment="Top" Width="46" Height="23"/>
        <Label Content="layers" HorizontalAlignment="Left" Margin="38,196,0,0" VerticalAlignment="Top" Width="46" Height="30"/>
        <Label Content="production pieces" HorizontalAlignment="Left" Margin="0,278,0,0" VerticalAlignment="Top" Width="108" Height="25"/>
        <TextBox x:Name="txtcode" Text="{Binding Txtcode, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="23" Margin="124,52,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtpieces" Text="{Binding Txtpieces, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="23" Margin="124,133,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtlayers" Text="{Binding Txtlayers,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="23" Margin="124,203,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <TextBox x:Name="txtproductionpieces" Text="{Binding Txtproductionpieces,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="23" Margin="124,280,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <ComboBox x:Name="comboBox1" Text="{Binding combobox1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="418,52,0,0" VerticalAlignment="Top" Width="319" Height="36" SelectionChanged="ComboBox1_SelectionChanged"/>
        <TextBox x:Name="txtseccond" Text="{Binding Txtseccond,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  HorizontalAlignment="Left" Height="23" Margin="124,345,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="141"/>
        <Label Content="seccond" HorizontalAlignment="Left" Margin="38,345,0,0" VerticalAlignment="Top" Width="46" Height="23"/>
        <TextBlock Text="{Binding A, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"  HorizontalAlignment="Left" Margin="418,133,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Height="23" Width="248"/>
        <TextBox Text="{Binding No1,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="21" Margin="426,210,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="303"/>


    </Grid>
</Window>

мои данные sql: введите описание изображения здесь

0 голосов
/ 08 января 2020

Насколько я понимаю, вы просто хотите сложить эти пять значений в TextBox, верно?

Если это так, вы можете сделать это несколькими способами ...

Один: Имейте свойство в классе SimpleMath, которое является суммой других значений, и свяжите это с TextBox. Вам придется обновлять свойство sum каждый раз, когда обновляется любое из этих пяти других значений.

Two: вы можете использовать IMultiValueConverter для суммирования значений, не имея больше свойств в классе SimpleMath. Это делается так:

Вы создаете класс, который реализует IMultiValueConverter inteface

public class SumConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        return values.Cast<int>()?.Sum()?.ToString();
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        return null;
    }
}

И используете его в XAML следующим образом

<TextBox>
    <TextBox.Resources>
        <local:SumConverter x:Key="SumConverter"/>
    </TextBox.Resources>
    <TextBox.Text>
        <MultiBinding Converter="{StaticResource SumConverter}">
            <Binding Path="Text" ElementName="OtherTextBox1" />
            <Binding Path="Text" ElementName="OtherTextBox2" />
            <Binding Path="Text" ElementName="OtherTextBox3" />
            <Binding Path="Text" ElementName="OtherTextBox4" />
            <Binding Path="Text" ElementName="OtherTextBox5" />
        </MultiBinding>
    </TextBox.Text>
</Control>

Надеюсь, это поможет

РЕДАКТИРОВАТЬ

Я сделал тестовый проект, чтобы показать вам полный код обоих предложенных мной решений, вот он:

Решение одно

using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;

namespace StackOverflowTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new SimpleMath();
        }
    }

    public class SimpleMath : INotifyPropertyChanged
    {
        private int _numberOne;
        public int NumberOne
        {
            get => _numberOne;
            set
            {
                _numberOne = value;
                OnPropertyChanged();
                CalculateSum();
            }
        }

        private int _numberTwo;
        public int NumberTwo
        {
            get => _numberTwo;
            set
            {
                _numberTwo = value;
                OnPropertyChanged();
                CalculateSum();
            }
        }

        private int _numberThree;
        public int NumberThree
        {
            get => _numberThree;
            set
            {
                _numberThree = value;
                OnPropertyChanged();
                CalculateSum();
            }
        }

        private int _numberSum;
        public int NumberSum
        {
            get => _numberSum;
            set
            {
                _numberSum = value;
                OnPropertyChanged();
            }
        }

        private void CalculateSum()
        {
            NumberSum = NumberOne + NumberTwo + NumberThree;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName()] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
<Window x:Class="StackOverflowTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:StackOverflowTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="200" Width="200">
    <StackPanel>
        <TextBox x:Name="TxtOne" HorizontalAlignment="Stretch" Text="{Binding NumberOne}" Margin="10,10,10,0"/>
        <TextBox x:Name="TxtTwo" HorizontalAlignment="Stretch" Text="{Binding NumberTwo}" Margin="10,10,10,0"/>
        <TextBox x:Name="TxtThree" HorizontalAlignment="Stretch" Text="{Binding NumberThree}" Margin="10,10,10,0"/>

        <TextBlock HorizontalAlignment="Center" Text="{Binding NumberSum}" Margin="10,10,10,0"/>
    </StackPanel>
</Window>

Решение два

using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Data;
using System.Collections.Generic;

namespace StackOverflowTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new SimpleMath();
        }
    }

    public class SimpleMath : INotifyPropertyChanged
    {
        private int _numberOne;
        public int NumberOne
        {
            get => _numberOne;
            set
            {
                _numberOne = value;
                OnPropertyChanged();
            }
        }

        private int _numberTwo;
        public int NumberTwo
        {
            get => _numberTwo;
            set
            {
                _numberTwo = value;
                OnPropertyChanged();
            }
        }

        private int _numberThree;
        public int NumberThree
        {
            get => _numberThree;
            set
            {
                _numberThree = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName()] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class SumConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var numbers = new List<int>();
            foreach (var item in values)
            {
                if(item is string stringValue)
                {
                    try
                    {
                        numbers.Add(System.Convert.ToInt32(stringValue));
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Oops, not a number...");
                    }
                }
            }

            return numbers.Sum().ToString();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
<Window x:Class="StackOverflowTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:StackOverflowTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="200" Width="200">
    <StackPanel>
        <TextBox x:Name="TxtOne" HorizontalAlignment="Stretch" Text="{Binding NumberOne}" Margin="10,10,10,0"/>
        <TextBox x:Name="TxtTwo" HorizontalAlignment="Stretch" Text="{Binding NumberTwo}" Margin="10,10,10,0"/>
        <TextBox x:Name="TxtThree" HorizontalAlignment="Stretch" Text="{Binding NumberThree}" Margin="10,10,10,0"/>

        <TextBlock HorizontalAlignment="Center" Margin="10,10,10,0">
            <TextBlock.Resources>
                <local:SumConverter x:Key="SumConverter"/>
            </TextBlock.Resources>
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource SumConverter}">
                    <Binding Path="Text" ElementName="TxtOne" />
                    <Binding Path="Text" ElementName="TxtTwo" />
                    <Binding Path="Text" ElementName="TxtThree" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </StackPanel>
</Window>

Вот как это выглядит

example

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...