System.Windows.Markup.XamlParseException:

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.
LVL 1
razza_bAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Gautham JanardhanConnect With a Mentor Commented:

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
 
Gautham JanardhanCommented:
can you post ur xaml please..
0
 
razza_bAuthor Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Gautham JanardhanCommented:
the signature for the click event and the completed event are different , you can use the same method for both
0
 
razza_bAuthor Commented:
Ok, that helped thanks, but for some reason when the button clicked it doesnt populate my grid ant ideas?
0
 
Gautham JanardhanCommented:
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
 
razza_bAuthor Commented:
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
 
razza_bAuthor Commented:
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
 
razza_bAuthor Commented:
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
 
Gautham JanardhanCommented:
what is sapGrid ? also can you make sure that e.Result has value in it
0
 
razza_bAuthor Commented:
thats the name of my grid.
0
 
razza_bAuthor Commented:
i cant get that far into that code before it bombs into the other code of main page
0
 
razza_bAuthor Commented:
e.result has the values
0
 
Gautham JanardhanCommented:
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
 
razza_bAuthor Commented:
no there are no errors being thrown, i thought it might be grid properties need set properly?
0
 
razza_bAuthor Commented:
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
 
razza_bAuthor Commented:
got it working just added extra grid properties

Thanks for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.