2010-12-11 11 views
0

Ich fand heraus, dass der Fehler bei der InitialisierungFehler System.Windows.Baml2006.TypeConverterMerkupExtension. Was könnte es sein?

Fehler auftritt. Bereitstellung von Mehrwert für System.Windows.Baml2006.TypeConverterMerkupExtension „verursachte eine Ausnahme Zeilennummer 8 und die Position in Reihe 9

Was könnte es sein, ?

<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(); 
     } 
    } 
} 

Antwort

1

Das Problem ist in Ihrem XAML, in der Icon Eigenschaft. Sie können einfach versuchen

Icon="Client.ico" 

anstelle des absoluten Pfad mit

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

Sie sind wahrscheinlich ein einzelnes Symbol für die gesamte Anwendung anstelle eines Symbols pro Fenster einrichten möchten. Weitere Informationen finden Sie in der MSDN-Referenznummer System.Windows.Window.Icon.

+0

Icon = "Client.ico" - nicht helfen. aber C# Uri iconUri = neuer Uri ("pack: // application: ,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute); this.Icon = BitmapFrame.Create (iconUri); geholfen! – Mediator

+0

Gut zu wissen, dass es geholfen hat. Sie können auch versuchen, den Pack Uri direkt auf XAML zu verwenden. – robertos

Verwandte Themen