none
Cartesian coordinate x y in wpf RRS feed

  • Question

  • Hi how i create Cartesian coordinate x y in  wpf so that it draws a graph on it by receiving input from the user?thanks.
    Thursday, December 12, 2019 10:31 AM

All replies

  • Hi,

    I use IValueConverter to create Cartesian coordinate x y,see my demo

      <Window.Resources>
            <local:XConvert x:Key="Xconvert"/>
            <local:YConvert x:Key="Yconvert"/>
        </Window.Resources>
        <StackPanel >
            <Canvas Width="200" Height="200" Name="Canvas1">
                <Line X1="0" Y1="100"  X2="200" Y2="100" Stroke="Black" ></Line>
               
                <Line X1="100" Y1="0" X2="100" Y2="200" Stroke="Black" ></Line>
    
                <Line X1="100" Y1="100" X2="{Binding ElementName=Textbox1,Path=Text,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource ResourceKey=Xconvert}}" Y2="{Binding ElementName=Textbox2,Path=Text,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource ResourceKey=Yconvert}}" Stroke="Black"></Line>
            </Canvas>
            <TextBox  Width="100" Name="Textbox1" Text="0"/>
            <TextBox Width="100" Margin="10" Name="Textbox2" Text="0"/>
            
        </StackPanel>
     public class XConvert : IValueConverter
        {
          
            
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                try
                {
                    int reValue = System.Convert.ToInt32(value);
                    return reValue + 100;
                }
                catch
                {
                    return 0;
                }
               
            }
    
     
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
              
                return 0;
            }
        }
        public class YConvert : IValueConverter
        {
    
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
    
                try
                {
                    int reValue = System.Convert.ToInt32(value);
                    return 100 - reValue;
                }
                catch
                {
                    return 100;
                }
    
    
            }
    
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
    
                return 0;
            }
        }

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, December 13, 2019 5:39 AM
    Moderator