错误System.Windows.Baml2006.TypeConverterMerkupExtension。会是什么呢?

时间:2010-12-11 13:42:40

标签: c# wpf xaml

我发现初始化期间发生了错误

错误: 为System.Windows.Baml2006.TypeConverterMerkupExtension提供值“导致异常。第8行和第9行中的位置

它可能是什么?

<Window x:Class="Client.Index"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:Client.index"
        Title="Главная программа"
        x:Name="window"
        KeyDown="window_KeyDown"
        WindowState="Maximized"
        Icon="/Client;component/Client.ico"
        >
    <Border x:Name="p_border">
        <ScrollViewer VerticalScrollBarVisibility="Auto" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" x:Name="gridrtfbox" Visibility="Collapsed">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                </Grid>
                <Grid Grid.Row="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="20" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <DockPanel x:Name="stack_d" Grid.Row="0"  Grid.ColumnSpan="4" VerticalAlignment="Stretch" >
                        <!--<l:CategoryView  />-->
                    </DockPanel>
                    <DockPanel x:Name="stack_trainer" Grid.Row="1"  Grid.ColumnSpan="4" DockPanel.Dock="Bottom" >
                        <!--<loc:TrainerView />-->
                    </DockPanel>

                    <Button Content="Почта" x:Name="mails"  Grid.Row="2" Grid.Column="0"  Width="100" HorizontalAlignment="Center" VerticalAlignment="Center"  Click="mails_Click"/>
                    <Button Content="Оплатить" Width="100" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"  Click="Button_Click_Payment"/>
                    <Button Content="Тех помощь" Width="100"  Grid.Row="2" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"  x:Name="support" Click="support_Click"/>
                    <Button Content="Настройки" x:Name="settings"  Grid.Row="2" Grid.Column="3"   Width="100" HorizontalAlignment="Center" VerticalAlignment="Center" Click="settings_Click"/>
                </Grid>
            </Grid>
        </ScrollViewer>
    </Border>
</Window>

C#:

using System;
using System.Windows;
using System.Windows.Input;
using System.Collections.ObjectModel;
using Client.payment;
using System.Data;
using MySql.Data.MySqlClient;
using DataBase;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Threading;
using SandboxApplication.Alerts;
using System.Linq;
using System.Windows.Media.Imaging;
using System.Net;
using System.IO;
using System.Windows.Media;


namespace Client
{
    /// <summary>
    /// Interaction logic for Index.xaml
    /// </summary>
    public partial class Index : Window
    {


        static public string idClient = "0";
        static public string idPersonClient = "0";

        static public DataTable dtPayment;
        //DATE_FORMAT(bday,'%d.%m.%Y') as bday

        //private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr SetWindowsHookEx(int id, LowLevelKeyboardProc callback, IntPtr hMod, uint dwThreadId);
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern bool UnhookWindowsHookEx(IntPtr hook);
        //[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr CallNextHookEx(IntPtr hook, int nCode, IntPtr wp, IntPtr lp);
        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        //private static extern IntPtr GetModuleHandle(string name);
        //[DllImport("user32.dll", CharSet = CharSet.Auto)]
        //private static extern short GetAsyncKeyState(System.Windows.Forms.Keys key);

        //private IntPtr ptrHook;
        //private LowLevelKeyboardProc objKeyboardProcess;


        Timer timer;

        public System.Windows.Controls.Border GetSetBorder
        {
            get { return p_border; }
            set { p_border = value; }
        }


        DateTime interval = new DateTime();


        string id = "";
        public void Update()
        {
            idPersonClient = id;
            MessageBox.Show("idPersonClient = id;");
            SetIdClient();
            MessageBox.Show(" SetIdClient();");
            DataPaymentGood(idClient);
            MessageBox.Show("DataPaymentGood(idClient);");
            string background_path = "";
            string myback = "";
            try
            {
                string sql = @"SELECT *";
                //string sql = @"SELECT  *";
                using (MySqlConnection connection = ConnectToDataBase.GetConnection())
                {
                    MySqlCommand command = new MySqlCommand(sql, connection);
                    // MySqlDataAdapter adapter = new MySqlDataAdapter();
                    connection.Open();
                    myback = command.ExecuteScalar().ToString();

                    if (File.Exists("images/" + myback) == false)
                    {
                        sql = @"SELECT *";
                        command = new MySqlCommand(sql, connection);
                        background_path = command.ExecuteScalar().ToString();
                        myback = background_path.Substring(background_path.LastIndexOf("/") + 1);
                        myback = "background" + myback;
                        string request = string.Format("{0}", background_path);
                        HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(request);
                        loHttp.Method = "GET";
                        loHttp.ProtocolVersion = HttpVersion.Version11;
                        HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();


                        using (StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream()))
                        {
                            System.Drawing.Image webImage = System.Drawing.Image.FromStream(loWebResponse.GetResponseStream());

                            webImage.Save(Directory.GetCurrentDirectory() + "/images/" + myback);
                            webImage.Dispose();
                        }
                        sql = "UPDATE *";
                        command = new MySqlCommand(sql, connection);


                        command = new MySqlCommand(sql, connection);
                        command.Parameters.Clear();
                        command.Parameters.AddWithValue("@background", myback);
                        command.Parameters.AddWithValue("@id", Index.idPersonClient);

                        int a = command.ExecuteNonQuery();
                    }


                    MessageBox.Show("int a = command.ExecuteNonQuery();");
                    //string back = background_path.Substring(background_path.LastIndexOf("/")-1);


                    // Create an ImageBrush

                    ImageBrush imgBrush = new ImageBrush();
                    imgBrush.ImageSource = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "/images/" + myback, UriKind.Absolute));
                    p_border.Background = imgBrush;
                    imgBrush = null;




                    //ImageSource imageSource = new BitmapImage(new Uri("images/background.jpg", UriKind.Relative));
                    //p_border.Background = new ImageBrush(imageSource);
                    //GetSetBorder.Background = null;

                }
                // idPersonClient
            }
            catch (NullReferenceException nullex)
            {
                //нет выбраного у польозвателя фона
                try
                {
                    string sql = @"SELECT path FROM Background LIMIT 1";
                    using (MySqlConnection connection = ConnectToDataBase.GetConnection())
                    {
                        MySqlCommand command = new MySqlCommand(sql, connection);
                        // MySqlDataAdapter adapter = new MySqlDataAdapter();
                        connection.Open();
                        background_path = command.ExecuteScalar().ToString();

                        string request = string.Format("{0}", background_path);
                        HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(request);
                        loHttp.Method = "GET";
                        loHttp.ProtocolVersion = HttpVersion.Version11;
                        HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();

                        StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream());
                        System.Drawing.Image webImage = System.Drawing.Image.FromStream(loWebResponse.GetResponseStream());

                        webImage.Save("images/background.jpg");

                        sql = "UPDATE *";
                        command = new MySqlCommand(sql, connection);
                        command.Parameters.Clear();
                        command.Parameters.AddWithValue("@id", Index.idClient);

                        int a = command.ExecuteNonQuery();

                        //System.Windows.Controls.Image finalImage = new  System.Windows.Controls.Image();
                        //BitmapImage logo = new BitmapImage();
                        //logo.BeginInit();
                        //logo.UriSource = new Uri("images/background.jpg");
                        //logo.EndInit();
                        //finalImage.Source = logo;







                        //FileStream fs = new FileStream("images/background.jpg", FileMode.Open);
                        //Image img = Image.FromStream(fs);
                        //fs.Close();


                        //ImageSource imageSource = Bitmap.FromFile();

                        // Create an ImageBrush
                        ImageBrush imgBrush = new ImageBrush();
                        imgBrush.ImageSource = new BitmapImage(new Uri("images/background.jpg", UriKind.Relative));


                        p_border.Background = imgBrush;
                    }
                }
                catch (NullReferenceException nullex2)
                {
                    //нет не одной записи в фоне
                    p_border.Background = null;
                }
                catch { }
            }
            catch (Exception ex) { }


            UpdateMessages();
            if (timer == null)
            {
                interval = DateTime.Parse(new TimeSpan(0, 0, 30).ToString());
                timer = new Timer(CheckMess, interval, 1000, long.Parse(interval.TimeOfDay.TotalSeconds.ToString()) * 1000);

            }

            try
            {

                //ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;
                //objKeyboardProcess = new LowLevelKeyboardProc(captureKey);
                //ptrHook = SetWindowsHookEx(13, objKeyboardProcess, GetModuleHandle(objCurrentModule.ModuleName), 0);
            }
            catch { return; }
        }
        public Index(string id)
        {
            this.id = id;
            MessageBox.Show("public Index(string id)");
            InitializeComponent();
            MessageBox.Show("  InitializeComponent();");



        }
        public void SetIdClient()
        {
            try
            {
                string sql = @"SELECT *";
                using (MySqlConnection connection = ConnectToDataBase.GetConnection())
                {
                    MySqlCommand command = new MySqlCommand(sql, connection);
                    // MySqlDataAdapter adapter = new MySqlDataAdapter();
                    connection.Open();
                    idClient = command.ExecuteScalar().ToString();
                }
                // idPersonClient
            }
            catch { MessageBox.Show("Произошла ошибка в SetIdClient, обратитесь к администрации или попробуйте перезайти - программа может работать не коректно"); }
        }
        //[StructLayout(LayoutKind.Sequential)]
        //private struct KBDLLHOOKSTRUCT
        //{
        //    public System.Windows.Forms.Keys key;
        //    public int scanCode;
        //    public int flags;
        //    public int time;
        //    public IntPtr extra;
        //}
        //static bool LWin = false;
        //private IntPtr captureKey(int nCode, IntPtr wp, IntPtr lp)
        //{
        //    if (nCode >= 0)
        //    {
        //        KBDLLHOOKSTRUCT objKeyInfo = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(KBDLLHOOKSTRUCT));
        //        if (objKeyInfo.key == System.Windows.Forms.Keys.PrintScreen) //здеся и перехватываем код клавиши
        //        {
        //            MessageBox.Show("Не шалить! ");
        //            if (Clipboard.ContainsImage())
        //            {
        //                Clipboard.Clear();
        //            }
        //            return (IntPtr)1;
        //        }
        //        else if (objKeyInfo.key == System.Windows.Forms.Keys.LWin)
        //        {
        //            LWin = true;
        //            return CallNextHookEx(ptrHook, nCode, wp, lp);
        //        }
        //        else if (objKeyInfo.key == System.Windows.Forms.Keys.D)
        //        {
        //            if (LWin)
        //            {
        //                return (IntPtr)1;
        //            }
        //        }
        //        LWin = false;
        //    }
        //    return CallNextHookEx(ptrHook, nCode, wp, lp);
        //}



        static public DataTable DataPaymentGood(string id)
        {
            try
            {
                DataSet temp = new DataSet();
                string sql = "SELECT *";
                using (MySqlConnection connection = ConnectToDataBase.GetConnection())
                {
                    MySqlCommand command = new MySqlCommand(sql, connection);
                    MySqlDataAdapter adapter = new MySqlDataAdapter();
                    connection.Open();
                    adapter.SelectCommand = command;
                    int count = adapter.Fill(temp, "Purchased");
                }
                dtPayment = temp.Tables["Purchased"];
                return dtPayment;
            }
            catch (Exception ex)
            {
                //Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
                MessageBox.Show(ex.Message);
                return null;
            }
        }
        static ObservableCollection<BasketTheme> basketTheme = new ObservableCollection<BasketTheme>();
        public static ObservableCollection<BasketTheme> GetBasketTheme { get { return basketTheme; } }

        static ObservableCollection<BasketTrainer> basketTrainer = new ObservableCollection<BasketTrainer>();
        public static ObservableCollection<BasketTrainer> GetBasketTrainer { get { return basketTrainer; } }

        private void Button_Click_Payment(object sender, RoutedEventArgs e)
        {
            try
            {
                Payment p = new Payment();
                p.ShowDialog();
            }
            catch { }
        }

        private void window_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.F5)
                {
                    Index i = new Index(idClient);
                    i.Show();
                    this.Close();
                }
                if (e.Key == Key.Escape)
                    this.Close();
            }
            catch { }
        }

        private void support_Click(object sender, RoutedEventArgs e)
        {
            Support s = new Support(this);
            s.Show();
        }

        private void mails_Click(object sender, RoutedEventArgs e)
        {
            Mail s = new Mail(this);
            s.Show();
        }




        #region Messages



        static ObservableCollection<Message> messages = new ObservableCollection<Message>();
        public static ObservableCollection<Message> GetMessages { get { return messages; } }
        DataSet dtSet = new DataSet();
        int total_messages = 0;
        public void ChekingMess()
        {
            try
            {
                string sql = @"SELECT *";
                using (MySqlConnection connection = ConnectToDataBase.GetConnection())
                {
                    MySqlCommand command = new MySqlCommand(sql, connection);
                    connection.Open();
                    int temp_total_messages = int.Parse(command.ExecuteScalar().ToString());

                    if (temp_total_messages > total_messages)
                    {

                        this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                        {
                            UpdateAll();
                            SimpleAlert am = new SimpleAlert();
                            am.Title = "У вас новое сообщение ";
                            am.Message = "Зайдите в сообщения";
                        }));
                    }
                }
            }
            catch { }
        }
        void CheckMess(object obj)
        {
            ChekingMess();
        }
        #region UPDATE
        public void UpdateMessages()
        {
            try
            {
                Helper.RemoveAll(GetMessages);

                string sql = @"SELECT *";
                total_messages = -1;
                if (dtSet.Tables["Messages"] != null)
                    dtSet.Tables["Messages"].Clear();
                using (MySqlConnection connection = ConnectToDataBase.GetConnection())
                {
                    MySqlCommand command = new MySqlCommand(sql, connection);
                    MySqlDataAdapter adapter = new MySqlDataAdapter();
                    connection.Open();
                    adapter.SelectCommand = command;
                    total_messages = adapter.Fill(dtSet, "Messages");

                }
                if (total_messages > 0)
                {
                    for (int i = 0; i < dtSet.Tables["Messages"].Rows.Count; i++)
                    {
                        int id = int.Parse(dtSet.Tables["Messages"].Rows[i].ItemArray[0].ToString());
                        int from_id = int.Parse(dtSet.Tables["Messages"].Rows[i].ItemArray[1].ToString());
                        string name_from = dtSet.Tables["Messages"].Rows[i].ItemArray[2].ToString();
                        int to_id = int.Parse(dtSet.Tables["Messages"].Rows[i].ItemArray[3].ToString());
                        string name_to = dtSet.Tables["Messages"].Rows[i].ItemArray[4].ToString();
                        string title = dtSet.Tables["Messages"].Rows[i].ItemArray[5].ToString();
                        string text = dtSet.Tables["Messages"].Rows[i].ItemArray[6].ToString();
                        DateTime send_date = new DateTime();
                        DateTime receive_date = new DateTime();
                        try
                        {
                            send_date = DateTime.Parse(dtSet.Tables["Messages"].Rows[i].ItemArray[7].ToString());
                        }
                        catch { }
                        try
                        {
                            receive_date = DateTime.Parse(dtSet.Tables["Messages"].Rows[i].ItemArray[8].ToString());
                        }
                        catch { }
                        Message f = new Message(id, from_id, name_from, to_id, name_to, title, text, send_date, receive_date);
                        messages.Add(f);
                    }
                }
                messages = new ObservableCollection<Message>(messages.OrderBy(Send_date => Send_date));
            }
            catch { }
        }
        void UpdateAll()
        {
            UpdateMessages();
            //UpdateClient();

            //UpdateAdmin();
            //UpdateClientNotPaid();
        }
        #endregion



        #endregion

        private void settings_Click(object sender, RoutedEventArgs e)
        {
            Settings s = new Settings(this);
            s.ShowDialog();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

问题出在您的XAML中,Icon属性中。您可以尝试使用

Icon="Client.ico"

而不是绝对路径

Icon="/Client;component/Client.ico"

您可能想为整个应用程序设置一个图标,而不是每个窗口设置一个图标。有关详细信息,请参阅System.Windows.Window.Icon上的MSDN参考。