none
Реализация public object[] ConvertBack, MultiBinding RRS feed

  • Вопрос

  • Делаю множественную привязку данных в TextBox через конвектор, из двух других textbox'ов, как реализовать обратный процесс? 

    public class ValueInFormulaConverter : IMultiValueConverter
      {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
          //вернуть общую стоимость товаров на складе
          double a = (double)values[0];
          double b = (double)values[1];
          //string formula = System.Convert.ToString(a);
          string formatFormula = String.Format("X^2/{0:F1} + Y^2/{1:F1}=1", a * a,b * b);
          return formatFormula;
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
          throw new NotSupportedException();
        }
    
    <Window x:Class="FormulaBindingConverter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:FormulaBindingConverter"
        Title="MainWindow" Height="350" Width="525">
        <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="73*" />
          <RowDefinition Height="238*" />
        </Grid.RowDefinitions>
        <Slider Name="SliderEllipseA" AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="1" LargeChange="2" 
            Margin="221,21,110,189" Maximum="100" Minimum="1" SmallChange="1" TickFrequency="10" TickPlacement="BottomRight" 
            Value="5" Grid.Row="1"/>
        <Slider Name="SliderEllipseB" AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="1" LargeChange="2" 
            Margin="221,76,110,134" Maximum="100" Minimum="1" SmallChange="1" TickFrequency="10" TickPlacement="BottomRight" 
            Value="10" Grid.Row="1" />
        <TextBox Name="TextBox1" Text="{Binding ElementName=SliderEllipseA, Path=Value, StringFormat=\{0:F2\}}" Margin="140,23,290,192" Grid.Row="1" />
        <TextBox Name="TextBox2" Text="{Binding ElementName=SliderEllipseB, Path=Value, StringFormat=\{0:F2\}}" Margin="140,74,290,140" Grid.Row="1" />
        <TextBox Margin="95,28,110,0" Background="Aquamarine" Name="TextBoxformula" AllowDrop="False" IsHitTestVisible="True">
          <TextBox.Text>
            <MultiBinding Converter="{StaticResource formulaConverter}" ConverterParameter="200">
              <Binding ElementName="SliderEllipseA" Path="Value"/>
              <Binding ElementName="SliderEllipseB" Path="Value" />
            </MultiBinding>
          </TextBox.Text>
        </TextBox>
        <Label Content="RadiusX" Grid.Row="1" HorizontalAlignment="Left" Margin="95,21,0,0" Name="label1" VerticalAlignment="Top" />
        <Label Content="RadiusY" HorizontalAlignment="Left" Margin="95,74,0,0" Name="label2" VerticalAlignment="Top" Grid.Row="1" />
      </Grid>
    </Window>
    
    

Ответы

Все ответы