编译器拒绝将Window转换为FrameworkElement

时间:2013-07-21 06:21:32

标签: c# .net wpf frameworkelement

我疯了吗?或者它是编译器?

我有:

Window w = new Window();

当我尝试使用期望FrameworkElement的函数时,编译器会抱怨:

  

无法从'System.Windows.Window'转换为   'System.Windows.FrameworkElement'

当我尝试w.Show()时,它会抱怨:

  

'System.Windows.Window'不包含'Show'的定义   没有扩展方法'显示'接受第一个参数   类型'System.Windows.Window'可以找到(你错过了使用   指令或程序集引用?)

但是,当我做intellisense“转到定义”时,我可以看到WindowContentControl的子类,它是FrameworkElement的子类,我可以看到Show()方法。

我甚至尝试过System.Windows.Window w = new System.Windows.Window()

发生了什么事?

编辑:代码示例(如果有帮助):

using System.Windows;

namespace MyApp
{
    public class MainViewModel
    {
        private void SomeMethod()
        {
            Window w = new Window();
            w.Show();
        }
    }
}

编辑2 :“CSProj”ItemGroup:

<ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.ComponentModel.Composition" />
    <Reference Include="System.Data" />
    <Reference Include="System.Windows.Interactivity" />
    <Reference Include="System.Xaml" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>

0 个答案:

没有答案
相关问题