这是我的整个代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void sldChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
double red, green, blue;
red = sldRed.Value;
green = sldGreen.Value;
blue = sldBlue.Value;
changeColors(red, green, blue);
}
private void inputChanged(object sender, TextChangedEventArgs e)
{
double red, green, blue;
red = Convert.ToDouble(txtRed.Text);
green = Convert.ToDouble(txtGreen.Text);
blue = Convert.ToDouble(txtBlue.Text);
sldRed.Value = red;
sldGreen.Value = green;
sldBlue.Value = blue;
changeColors(red, green, blue);
}
void changeColors(double red, double green, double blue)
{
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
txtRed.Text = Convert.ToString(sldRed.Value);
txtGreen.Text = Convert.ToString(sldGreen.Value);
txtBlue.Text = Convert.ToString(sldBlue.Value);
}
}
这是我的整个 .xaml 代码。
<Grid x:Name="frmGrid" Margin="0,0,2,0">
<Slider x:Name="sldRed" HorizontalAlignment="Left" Margin="57,10,0,0" VerticalAlignment="Top" Width="757" ValueChanged="sldChanged" ClipToBounds="True" Maximum="255" TickPlacement="BottomRight" IsSnapToTickEnabled="True" SmallChange="1" Value="1"/>
<Slider x:Name="sldBlue" HorizontalAlignment="Left" Margin="57,76,0,0" VerticalAlignment="Top" Width="757" ValueChanged="sldChanged" ClipToBounds="True" Maximum="255" TickPlacement="BottomRight" IsSnapToTickEnabled="True" SmallChange="1" Value="1"/>
<Slider x:Name="sldGreen" HorizontalAlignment="Left" Margin="57,45,0,0" VerticalAlignment="Top" Width="757" ValueChanged="sldChanged" ClipToBounds="True" Maximum="255" TickPlacement="BottomRight" IsSnapToTickEnabled="True" SmallChange="1" Value="1"/>
<Label Content="Red" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<Label Content="Blue" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top"/>
<Label Content="Green" HorizontalAlignment="Left" Margin="10,41,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="txtRed" HorizontalAlignment="Left" Height="23" Margin="819,9,0,0" TextWrapping="Wrap" Text="1" VerticalAlignment="Top" Width="41" TextChanged="inputChanged"/>
<TextBox x:Name="txtBlue" HorizontalAlignment="Left" Height="23" Margin="819,74,0,0" TextWrapping="Wrap" Text="1" VerticalAlignment="Top" Width="41" TextChanged="inputChanged"/>
<TextBox x:Name="txtGreen" HorizontalAlignment="Left" Height="23" Margin="819,41,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="41" TextChanged="inputChanged" Text="1"/>
</Grid>
您可以看到我已经为这些文本框分配了一个值以用于测试目的。
出于某种原因,我不断收到此错误
其中指的是这两行。
green = Convert.ToDouble(txtGreen.Text);
blue = Convert.ToDouble(txtBlue.Text);
请注意它上面的类似行如何完美地工作
red = Convert.ToDouble(txtRed.Text);
我还没有 C# 方面的经验,也没有阅读此类错误的经验。如果您对我收到此错误的原因有任何想法,并可能为我提供可能的解决方案,我们将不胜感激。
PS:我刚刚认为可能对您有用的东西,我什至在程序启动之前就收到了这个错误。
这是 2 个屏幕截图,其中 1 个根本没有加载,而第 2 个可以完美加载并且可以正常工作。