2012-04-26 78 views
0

我寫了一個代碼在wpf顯示指數,通過接受兩個數字 因爲我已經創建了一個轉換器功能和代碼..但是當寫完這個後代碼它顯示錯誤,如 「Microsoft Visual Studio遇到問題,它必須關閉」..然後當我們點擊不要發送它關閉Vs2010。 這可能是什麼問題?代碼接在這裏......爲什麼VisualStudio關閉時,我寫這個Wpf xmal代碼

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> 
+0

當您重新打開VS會發生什麼由ObjectDataProvider參考呢? – 2012-04-26 09:19:46

回答

1

回答

也許是因爲計算器的?你參考Exponential類的方法Exponential類'ObjectDataProvider,它創建Exponential類實例,它實例化ObjectDataProvider等。

說明

ObjectDataProvider結合的方法需要實例化類,包含該方法調用它。這就是爲什麼你有無盡的復發。在一個單獨的類

解決方法

廣場方法和Exponential.xaml

+0

同意,由於堆棧溢出導致VS崩潰。 – GazTheDestroyer 2012-04-26 11:12:13

+0

是的,VS xaml的設計師並沒有處理它 – EvAlex 2012-04-26 11:48:06

+0

謝謝...它工作正常 – 2012-04-28 09:40:54