【发布时间】:2015-06-19 11:57:10
【问题描述】:
您好,我正在尝试从 3 种不同的控件类型(文本框、单选按钮和滑块)中获取值,以计算贷款的每月付款。我无法获取单选按钮和滑块的值。
如果选中其他,则有 3 个年份单选按钮(15,30,其他),然后用户在文本框中输入年份。
滑块收集利率。我不确定如何获得用户滑动的价值。
输出应该在标签中。
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
}
void radiobutton_CheckChanged(object sender, RoutedEventArgs e)
{
//txtYears.IsEnabled = btn3.IsChecked;
}
private void sldRate_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
}
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
double p, yrs, r, m;
double.TryParse(txtPrin.Text, out p);
foreach (RadioButton button in stkYears.Children)
{
if (button.IsChecked.Value)
{
if (button.Content.ToString() == "Other")
txtYears.IsEnabled = btn3.IsChecked;
}
}
double.TryParse(txtYears.Text, out yrs);
m = (txtPrin * )
//the above statment should look like this
//m = (p * r / 1200.0) / (1 - Math.Pow((1.0 + r / 1200.0), (-12 * yrs)));
lblMonthlyPayment.TextInput = m.ToString();
}
下面是xaml
<Label Content="Number Of Years" HorizontalAlignment="Left" VerticalAlignment="Top" Width="175" FontFamily="NSimSun" FontSize="14" Height="26" Grid.Row="1" Margin="0,28,0,0"/>
<StackPanel Grid.Column="1" Name="stkYears" Margin="0,6,0,0" Grid.Row="1">
<RadioButton x:Name="btn1" GroupName="Years" Content="15 Years" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="99" Height="15" FontFamily="Shruti" Grid.Column="1" Grid.Row="1"/>
<RadioButton GroupName="Years" Content="30 Years" HorizontalAlignment="Left" Margin="10,1,0,0" VerticalAlignment="Top" Width="99" Height="15" FontFamily="Shruti" />
<RadioButton x:Name="btn3" GroupName="Years" Checked="radioButton_CheckChanged" Unchecked="radioButton_CheckChanged" Content="Other" HorizontalAlignment="Left" Margin="10,1,0,0"
VerticalAlignment="Top" Width="99" Height="15" FontFamily="Shruti" IsChecked="True"/>
<TextBox x:Name="txtYears" Height="17" Margin="30,0,168,0"/>
</StackPanel>
<Label Content="Interest Rate" HorizontalAlignment="Left" Margin="0,27,0,0" VerticalAlignment="Top" Width="188" FontFamily="NSimSun" FontSize="14" Height="24" Grid.Row="2" Grid.ColumnSpan="2"/>
<Slider HorizontalAlignment="Left" Name="sldRate" IsSnapToTickEnabled="True" TickPlacement="BottomRight"
AutoToolTipPlacement="BottomRight" TickFrequency="3"
AutoToolTipPrecision="2" IsDirectionReversed="False"
IsMoveToPointEnabled="False" Margin="13,27,-18,0" VerticalAlignment="Top" Width="291" Minimum="0" Maximum="6" Ticks="0, 1, 2, 3, 4, 5, 6" ValueChanged="sldRate_ValueChanged" Height="51" Background="White" Foreground="Black" BorderBrush="#00000000" Grid.Column="1" Grid.Row="2"/>
<Button Name ="btnSubmit" Content="Calculate Monthly Payment" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="165" Click="btnSubmit_Click" Height="30" Grid.Row="3" RenderTransformOrigin="0.5,0.5"/>
<Label x:Name="lblMonthlyPayment" Content="" Grid.Column="1" HorizontalAlignment="Left" Margin="13,15,0,0" Grid.Row="3" VerticalAlignment="Top" Width="124" IsEnabled="False" />
【问题讨论】:
-
“遇到麻烦”是怎么回事?
-
你的问题是什么?
-
@PhilGref 如何获取单选按钮和滑块的值?
标签: c# xaml slider radio-button wpf-controls