razza_b
asked on
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.Xaml ParseExcep tion: Failed to assign to property 'System.Windows.Controls.P rimitives. 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<SalesListComp letedEvent Args>(sapD ata_Click) ;
client.SalesListAsync();
}
private void sapData_Click(object sender, SalesListCompletedEventArg s e) {
sapGrid.ItemsSource = e.Result;
}
}
}
Im basically trying to populate a grid from a button event.
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.Xaml
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<SalesListComp
client.SalesListAsync();
}
private void sapData_Click(object sender, SalesListCompletedEventArg
sapGrid.ItemsSource = e.Result;
}
}
}
Im basically trying to populate a grid from a button event.
can you post ur xaml please..
ASKER
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-name space:Syst em.Windows .Controls; assembly=S ystem.Wind ows.Contro ls.Navigat ion"
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>
<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-name
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
</StackPanel>
</ScrollViewer>
</Grid>
</navigation:Page>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the signature for the click event and the completed event are different , you can use the same method for both
ASKER
Ok, that helped thanks, but for some reason when the button clicked it doesnt populate my grid ant ideas?
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
ASKER
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, SalesListCompletedEventArg s e)
{
try
{
sapGrid.ItemsSource = e.Result;
}
catch
{
HtmlPage.Window.Alert("NO DATA!");
}
}
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, SalesListCompletedEventArg
{
try
{
sapGrid.ItemsSource = e.Result;
}
catch
{
HtmlPage.Window.Alert("NO DATA!");
}
}
ASKER
this is my other code involved...
namespace SLERPConn.Web
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequir ements(Req uirementsM ode = AspNetCompatibilityRequire mentsMode. Allowed)]
public class Service1
{
[OperationContract]
public List<SalesOrder> SalesList()
{
string Cnn = System.Configuration.Confi gurationMa nager.Conn ectionStri ngs["WTCn" ].Connecti onString;
var sales = new List<SalesOrder>();
using (SqlConnection conn = new SqlConnection(Cnn))
{
const string sql = @"SELECT TOP 10 salesorder, partnumber, qty FROM wp4tbl_TblSAPSilverlightTe st";
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
SqlDataReader dr = cmd.ExecuteReader(CommandB ehavior.Cl oseConnect ion);
if (dr != null)
while (dr.Read())
{
var data = new SalesOrder
{
salesorder = dr.GetString(0),
partnumber = dr.GetString(1),
qty = Convert.ToString(dr.GetInt 32(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; }
}
}
namespace SLERPConn.Web
{
[ServiceContract(Namespace
[AspNetCompatibilityRequir
public class Service1
{
[OperationContract]
public List<SalesOrder> SalesList()
{
string Cnn = System.Configuration.Confi
var sales = new List<SalesOrder>();
using (SqlConnection conn = new SqlConnection(Cnn))
{
const string sql = @"SELECT TOP 10 salesorder, partnumber, qty FROM wp4tbl_TblSAPSilverlightTe
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
SqlDataReader dr = cmd.ExecuteReader(CommandB
if (dr != null)
while (dr.Read())
{
var data = new SalesOrder
{
salesorder = dr.GetString(0),
partnumber = dr.GetString(1),
qty = Convert.ToString(dr.GetInt
};
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; }
}
}
ASKER
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<SalesListComp letedEvent Args>(sapD ata_Comple ted);
client.SalesListAsync();
}
private void sapData_Completed(object sender, SalesListCompletedEventArg s 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(obj ect 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.ToStri ng()))
{
VisualStateManager.GoToSta te(hb, "ActiveLink", true);
}
else
{
VisualStateManager.GoToSta te(hb, "InactiveLink", true);
}
}
}
}
// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFai led(object sender, NavigationFailedEventArgs e)
{
e.Handled = true;
ChildWindow errorWin = new ErrorWindow(e.Uri);
errorWin.Show();
}
}
then nothing appears.
public Home()
{
InitializeComponent();
Service1Client client = new Service1Client();
client.SalesListCompleted += new EventHandler<SalesListComp
client.SalesListAsync();
}
private void sapData_Completed(object sender, SalesListCompletedEventArg
{
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(obj
{
foreach (UIElement child in LinksStackPanel.Children)
{
HyperlinkButton hb = child as HyperlinkButton;
if (hb != null && hb.NavigateUri != null)
{
if (hb.NavigateUri.ToString()
{
VisualStateManager.GoToSta
}
else
{
VisualStateManager.GoToSta
}
}
}
}
// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFai
{
e.Handled = true;
ChildWindow errorWin = new ErrorWindow(e.Uri);
errorWin.Show();
}
}
then nothing appears.
what is sapGrid ? also can you make sure that e.Result has value in it
ASKER
thats the name of my grid.
ASKER
i cant get that far into that code before it bombs into the other code of main page
ASKER
e.result has the values
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...
ASKER
no there are no errors being thrown, i thought it might be grid properties need set properly?
ASKER
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.ArgumentNullExcepti on: Value cannot be null.
Parameter name: binding
at System.Windows.Data.Bindin gOperation s.SetBindi ng(Depende ncyObject target, DependencyProperty dp, BindingBase binding)
at System.Windows.FrameworkEl ement.SetB inding(Dep endencyPro perty dp, Binding binding)
at System.Windows.Controls.Da taGridText Column.Gen erateEleme nt(DataGri dCell cell, Object dataItem)
at System.Windows.Controls.Da taGridColu mn.Generat eElementIn ternal(Dat aGridCell cell, Object dataItem)
at System.Windows.Controls.Da taGrid.Pop ulateCellC ontent(Boo lean isCellEdited, DataGridColumn dataGridColumn, DataGridRow dataGridRow, DataGridCell dataGridCell)
at System.Windows.Controls.Da taGrid.Add NewCellPri vate(DataG ridRow row, DataGridColumn column)
at System.Windows.Controls.Da taGrid.Com pleteCells Collection (DataGridR ow dataGridRow)
at System.Windows.Controls.Da taGrid.Gen erateRow(I nt32 rowIndex, Int32 slot, Object dataContext)
at System.Windows.Controls.Da taGrid.Gen erateRow(I nt32 rowIndex, Int32 slot)
at System.Windows.Controls.Da taGrid.Add Slots(Int3 2 totalSlots)
at System.Windows.Controls.Da taGrid.Ref reshRows(B oolean recycleRows, Boolean clearRows)
at System.Windows.Controls.Da taGrid.Ref reshRowsAn dColumns(B oolean clearRows)
at System.Windows.Controls.Da taGrid.Mea sureOverri de(Size availableSize)
at System.Windows.FrameworkEl ement.Meas ureOverrid e(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
Line: 57
Char: 13
Code: 0
URI: http://localhost:62381/SLERPConnTestPage.aspx
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.ArgumentNullExcepti
Parameter name: binding
at System.Windows.Data.Bindin
at System.Windows.FrameworkEl
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.Controls.Da
at System.Windows.FrameworkEl
Line: 57
Char: 13
Code: 0
URI: http://localhost:62381/SLERPConnTestPage.aspx
ASKER
got it working just added extra grid properties
Thanks for your help!
Thanks for your help!