0

我在 wpf 中编写了一个代码来显示指数,通过接受这两个数字,我创建了一个转换器函数和代码.. 但是在编写此代码后它显示错误,例如“Microsoft Visual Studio 遇到问题,它必须关闭”..然后当我们点击不发送时,它会关闭 Vs2010。这可能是什么问题?代码附在这里...

namespace WpfTutSamples
{

    public partial class Exponential : Window
    {
        public Exponential()
        {
            InitializeComponent();
        }
        public double GetValue(double number, double exponent)
        {
            double value = Math.Pow(number, exponent);
            return value;

        }
    }
}

-----XmlCode

<Window x:Class="WpfTutSamples.Exponential"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfTutSamples"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Exponential" Height="300" Width="300">

    <Window.Resources>
        <ObjectDataProvider x:Key="expCalculator" MethodName="GetValue" ObjectType="{x:Type local:Exponential}">
            <ObjectDataProvider.MethodParameters>
                <sys:Double>4</sys:Double>
                <sys:Double>2</sys:Double>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>


    <Grid>

        <Label Content="Number" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2"> </Label>

        <TextBox HorizontalAlignment="Left" x:Name="txtNumber" Height="30" VerticalAlignment="Top" Margin="70,1" Width="60"
                 Text="{Binding Source={StaticResource expCalculator}, Path=MethodParametes[0], Mode=OneWayToSource, BindsDirectlyToSource=True}"></TextBox>


        <Label Content="Number" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2,40"> </Label>
        <TextBox HorizontalAlignment="Left" x:Name="txtpower" Height="30" VerticalAlignment="Top" Margin="70,40" Width="60"
                 Text="{Binding Source={StaticResource expCalculator}, Path=MethodParametes[1], Mode=OneWayToSource, BindsDirectlyToSource=True}"></TextBox>


<Label Content="Result" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2,80"> </Label>
        <TextBox HorizontalAlignment="Left" x:Name="txtResult" Height="30" VerticalAlignment="Top" Margin="70,80" Width="60"
                 Text="{Binding Source={StaticResource expCalculator}}"></TextBox>

    </Grid>
</Window>
4

1 回答 1

1

回答

也许是因为stackoverflow?您从class'引用Exponentialclass' 方法,该方法创建类实例,实例化等等。ExponentialObjectDataProviderExponentialObjectDataProvider

解释

ObjectDataProvider绑定到方法需要实例化类,包含调用它的方法。这就是为什么你有无穷无尽的重复。

解决方法

ObjectDataProvider将方法放在一个单独的类中并在 Exponential.xaml 中引用它

于 2012-04-26T10:32:32.390 回答