Solved

System.Windows.Markup.XamlParseException:

Posted on 2010-11-10
17
2,706 Views
Last Modified: 2013-11-12
Hi

Ive created a silverlight navigation project and it consists of a web project with my svc file with its C# code etc and i have contained my silverlight page within my master page content, but when im running my app i get the error System.Windows.Markup.XamlParseException: Failed to assign to property 'System.Windows.Controls.Primitives.ButtonBase.Click'

this is the code it fails at...

namespace SLERPConn
{
    public partial class Home : Page
    {
        public Home()
        {
            InitializeComponent(); FAILS AT THIS LINE

            Service1Client client = new Service1Client();
            client.SalesListCompleted += new EventHandler<SalesListCompletedEventArgs>(sapData_Click);
            client.SalesListAsync();
        }

        private void sapData_Click(object sender, SalesListCompletedEventArgs e)         {
            sapGrid.ItemsSource = e.Result;
        }
    }
}

Im basically trying to populate a grid from a button event.
0
Comment
Question by:razza_b
  • 11
  • 6
17 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 34109205
can you post ur xaml please..
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110192
sure...

<navigation:Page x:Class="SLERPConn.Home"
    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:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    Title="Home"
    Style="{StaticResource PageStyle}" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid x:Name="LayoutRoot">
        <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">

            <StackPanel x:Name="ContentStackPanel">

                <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"
                                   Text="Home"/>
                <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}"
                                   Text="Home page content"/>
                <Button Content="SAP Data" Height="23" Name="button1" Width="75" Click="sapData_Click" />
                <sdk:DataGrid AutoGenerateColumns="False" Height="86" Name="sapGrid" Width="565" />
            </StackPanel>

        </ScrollViewer>
    </Grid>

</navigation:Page>
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 34110235

namespace SLERPConn

{

    public partial class Home : Page

    {

        public Home()

        {

            InitializeComponent(); FAILS AT THIS LINE



            Service1Client client = new Service1Client();

            client.SalesListCompleted += new EventHandler<SalesListCompletedEventArgs>(sapData_Completed);

            client.SalesListAsync();

        }



        private void sapData_Completed(object sender, SalesListCompletedEventArgs e)         {

            sapGrid.ItemsSource = e.Result;

        }



        private void sapData_Click(object sender, RoutedEventArgs e)         {



        }

    }

} 

Open in new window

0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 34110241
the signature for the click event and the completed event are different , you can use the same method for both
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110315
Ok, that helped thanks, but for some reason when the button clicked it doesnt populate my grid ant ideas?
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 34110532
the click method doesnt have any implementation, Not sure what the button is though, From my understanding the grid should get populated on the call back from the service
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110568
I was going to use it to click and populate it(obviously no code in it to do that so ill remove it) but yeah the service should just populate it.

i added this in to see if anything happens but nothing does happen. Do you know why it wont populate?

private void sapData_Completed(object sender, SalesListCompletedEventArgs e)
        {
            try
            {
                sapGrid.ItemsSource = e.Result;
            }
            catch
            {
                HtmlPage.Window.Alert("NO DATA!");
            }
        }
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110598
this is my other code involved...

namespace SLERPConn.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1
    {
        [OperationContract]
        public List<SalesOrder> SalesList()
        {
            string Cnn = System.Configuration.ConfigurationManager.ConnectionStrings["WTCn"].ConnectionString;
            var sales = new List<SalesOrder>();
            using (SqlConnection conn = new SqlConnection(Cnn))
            {
                const string sql = @"SELECT TOP 10 salesorder, partnumber, qty FROM wp4tbl_TblSAPSilverlightTest";
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (dr != null)
                        while (dr.Read())
                        {
                            var data = new SalesOrder
                            {
                                salesorder = dr.GetString(0),
                                partnumber = dr.GetString(1),
                                qty = Convert.ToString(dr.GetInt32(2))
                            };
                            sales.Add(data);
                        }
                    return sales;
                }
            }
        }
    }
}


namespace SLERPConn.Web.Classes
{
    public class SalesOrder
    {
        public string salesorder { get; set; }
        public string partnumber { get; set; }
        public string qty { get; set; }
    }
}
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:razza_b
ID: 34110671
when im debugging the service it has the data to pull back for the grid, but when going through this code

public Home()
        {
            InitializeComponent();
           
            Service1Client client = new Service1Client();
            client.SalesListCompleted += new EventHandler<SalesListCompletedEventArgs>(sapData_Completed);
            client.SalesListAsync();
        }

        private void sapData_Completed(object sender, SalesListCompletedEventArgs e)
        {
            try
            {
                sapGrid.ItemsSource = e.Result;
            }
            catch
            {
                HtmlPage.Window.Alert("NO DATA!");
            }
        }
    }

it gets to sapData_Completed method then goes into main page xaml cs...

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        // After the Frame navigates, ensure the HyperlinkButton representing the current page is selected
        private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
        {
            foreach (UIElement child in LinksStackPanel.Children)
            {
                HyperlinkButton hb = child as HyperlinkButton;
                if (hb != null && hb.NavigateUri != null)
                {
                    if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
                    {
                        VisualStateManager.GoToState(hb, "ActiveLink", true);
                    }
                    else
                    {
                        VisualStateManager.GoToState(hb, "InactiveLink", true);
                    }
                }
            }
        }

        // If an error occurs during navigation, show an error window
        private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            ChildWindow errorWin = new ErrorWindow(e.Uri);
            errorWin.Show();
        }
    }

then nothing appears.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 34110689
what is sapGrid ? also can you make sure that e.Result has value in it
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110703
thats the name of my grid.
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110711
i cant get that far into that code before it bombs into the other code of main page
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110725
e.result has the values
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 34110783
the other page throws error is it ? can you post that... i cant find any reason why if e.result has values it wont sow up in the grid...
0
 
LVL 1

Author Comment

by:razza_b
ID: 34110869
no there are no errors being thrown, i thought it might be grid properties need set properly?
0
 
LVL 1

Author Comment

by:razza_b
ID: 34111042
when i run without any breakpoints the page appears with empty grid then the just in time debugger appears, when i click no grid disapears and on bottom left of browser window it has error, when i double click it the error inside is...

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
Timestamp: Thu, 11 Nov 2010 12:58:39 UTC


Message: Unhandled Error in Silverlight Application
Code: 4004    
Category: ManagedRuntimeError      
Message: System.ArgumentNullException: Value cannot be null.
Parameter name: binding
   at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
   at System.Windows.FrameworkElement.SetBinding(DependencyProperty dp, Binding binding)
   at System.Windows.Controls.DataGridTextColumn.GenerateElement(DataGridCell cell, Object dataItem)
   at System.Windows.Controls.DataGridColumn.GenerateElementInternal(DataGridCell cell, Object dataItem)
   at System.Windows.Controls.DataGrid.PopulateCellContent(Boolean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell)
   at System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow row, DataGridColumn column)
   at System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow dataGridRow)
   at System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext)
   at System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot)
   at System.Windows.Controls.DataGrid.AddSlots(Int32 totalSlots)
   at System.Windows.Controls.DataGrid.RefreshRows(Boolean recycleRows, Boolean clearRows)
   at System.Windows.Controls.DataGrid.RefreshRowsAndColumns(Boolean clearRows)
   at System.Windows.Controls.DataGrid.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)    

Line: 57
Char: 13
Code: 0
URI: http://localhost:62381/SLERPConnTestPage.aspx

0
 
LVL 1

Author Comment

by:razza_b
ID: 34111400
got it working just added extra grid properties

Thanks for your help!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now