空例外 - 未在WPF中调用

时间:2016-05-12 11:07:52

标签: wpf

Visual Studio 2015调试

在XAML中出现错误

xmlns:local="clr-namespace:Poker"

错误是XMLParseException,然后是System.Core.DLL中的SystemArgumentNullException

Poker.MainWindow的ctor永远不会被称为 App.xaml.cs被调用,但它什么也没做 下一步是xmlns上的错误:local
这是我已经工作了几个星期没有问题的应用程序

清洁,重建显示没有错误
运行代码分析发现没有错误
我认为有一些关于运行时解析的东西正在打破它。

如果我删除xmlns:local我可以通过浏览到扑克来添加它

其他应用程序在此PC上运行正常 PC没有崩溃

有人要求代码

<Window x:Class="Poker.MainWindow"      
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Poker"
    mc:Ignorable="d"
    ResizeMode="NoResize"          
    DataContext="{Binding RelativeSource={RelativeSource self}}"
    Title="No Limit Holdem Poker 6 Player Sit And Go (SNG) - Beat the Bots" Height="600" Width="650">
<Window.Resources>
    <BooleanToVisibilityConverter x:Key="bvc" />
    <local:BackGroundConverter x:Key="backGroundConverter"/>
    <local:BackGroundConverterCard x:Key="backGroundConverterCard"/>
    <local:BackGroundConverterSuit x:Key="backGroundConverterSuite"/>
    <Style TargetType="TextBlock">
        <Setter Property="FontSize" Value="20"/>
    </Style>
    <Style TargetType="TextBlock" x:Key="StdMargin">
        <Setter Property="FontSize" Value="18"/>
        <Setter Property="Margin" Value="16,0,0,0"/>
    </Style>
    <Style TargetType="TextBlock" x:Key="StdMarginPlus">
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="Margin" Value="24,0,0,0"/>
    </Style>
    <Style TargetType="ComboBox">
        <Setter Property="FontSize" Value="18"/>
    </Style>
    <Color x:Key="ColorMyLighLightGray">#EDEDED</Color>
    <SolidColorBrush x:Key="BrushMyLightLightGrey"  Color="{StaticResource ColorMyLighLightGray}"/>
</Window.Resources>
<Grid Margin="10,0,2,0">
</Grid>
</Window>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Diagnostics;
//using System.Threading;

namespace Poker
{

    public enum enumSuite : byte { spade = 0, club = 1, heart = 3, diamond = 4, none = 5 };
    public enum enumRank : byte { one = 1, two = 2, three = 3, four = 4, five = 5, six = 6, seven = 7, eight = 8, nine = 9, ten = 10, jack = 11, queen = 12, king = 13, ace = 14 };
    public enum enumHand : byte { high = 0, onePair = 1, twoPair = 2, trip = 3, straight = 4, flush = 5, boat = 6, quad = 7, strtFlush = 8 };
    public enum enumHandDraw : byte { onePair = 1, twoPairTrips = 2, straight = 4, flush = 5, boat = 6, quad = 7, strtFlush = 8 };
    public enum enumPlayerType : byte { callSn = 0, rock = 1, GTO = 2 };

    // 0 nothing
    // 1 pair
    // 2 pair
    // 3 trips
    // 4 straight 
    // 5 flush
    // 6 boat
    // 7 four of a kind 
    // 8 straight flush 

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public MainWindow()
        {
            Debug.WriteLine("ctor");  // does not get called
            //LoopCount();
            ProcessShuffle();
            EveryOneBet(0, true);
            before = false;
            InitializeComponent();
        }

1 个答案:

答案 0 :(得分:1)

我没有发布所有代码

实际上它出现在

背后的代码中

我有

namespace 
{
    MainWindow
    {
    }
    public class 
    {
    }
}

我将一个类移到主窗口中以访问静态变量
并且在没有编译器错误的情况下严重破坏了

namespace 
{
    MainWindow
    {
        public class 
        {
        }
    }
}