Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

getting baml exception regularly...

Closed Thread
 
Thread Tools Display Modes
Old 03-06-2006   #1 (permalink)
madhur
Guest


 

getting baml exception regularly...

Hello

I am getting a baml exception every time a use a control inside my code
behind file. For ex consider this xaml code :

<Window x:Class="WindowsApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
Title="WindowsApplication1" Width="550" Height="400">
<Window.Resources>
<!-- define the XML data source as a resource -->
<XmlDataProvider x:Key="BookmarkData" Source="XMLFile1.xml"
XPath="/Favorites">

</XmlDataProvider>

<!-- create a data template to display the desired XML node values
-->
<DataTemplate x:Key="BookmarkDataTemplate">
<StackPanel Margin="5">
<TextBlock FontSize="12" FontWeight="Bold" Foreground="White">
<TextBlock.Text>
<Binding XPath="Title"/>
</TextBlock.Text>
</TextBlock>
<TextBlock FontSize="10" Foreground="LightGray">
<TextBlock.Text>
<Binding XPath="URL"/>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</DataTemplate>
</Window.Resources>

<!-- write the data to the screen by binding the data template to a
list box -->
<StackPanel>
<TextBlock FontSize="14" FontWeight="Bold" Margin="10">My
Favorites</TextBlock>
<ListBox x:Name="listbox1"
BorderThickness="2"
BorderBrush="White"
Margin="10"
ItemsSource="{Binding Source={StaticResource BookmarkData},
XPath=Bookmark}"
ItemTemplate="{StaticResource BookmarkDataTemplate}"/>
</StackPanel>

</Window>

And see the code behind file :

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace WindowsApplication1
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>

public partial class Window1 : Window
{
//int [] values;
public Window1()
{
// values=new int[10];
InitializeComponent();

// int i=listbox1.Items.Count;

}


}
}

Every time I uncomment this line // int i=listbox1.Items.Count;
I get a baml exception ....

Can anyone help me....

Old 03-06-2006   #2 (permalink)
Sheva
Guest


 

Re: getting baml exception regularly...

I think you can write an event handler which will hooks up to Window's
Loaded event, and put that line of code into this event handler:
for instance:
in xaml, you do this:
<Window Loaded="WindowLoadedEventHandler">
and in code you do this:
private void WindowLoadedEventHandler(Object sender, RoutedEventArgs e)
{
// int i=listbox1.Items.Count;
}

Sheva
"madhur" <ahuja.madhur@gmail.com> wrote in message
news:1141640410.933322.18340@u72g2000cwu.googlegroups.com...
> Hello
>
> I am getting a baml exception every time a use a control inside my code
> behind file. For ex consider this xaml code :
>
> <Window x:Class="WindowsApplication1.Window1"
> xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
> xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
> Title="WindowsApplication1" Width="550" Height="400">
> <Window.Resources>
> <!-- define the XML data source as a resource -->
> <XmlDataProvider x:Key="BookmarkData" Source="XMLFile1.xml"
> XPath="/Favorites">
>
> </XmlDataProvider>
>
> <!-- create a data template to display the desired XML node values
> -->
> <DataTemplate x:Key="BookmarkDataTemplate">
> <StackPanel Margin="5">
> <TextBlock FontSize="12" FontWeight="Bold" Foreground="White">
> <TextBlock.Text>
> <Binding XPath="Title"/>
> </TextBlock.Text>
> </TextBlock>
> <TextBlock FontSize="10" Foreground="LightGray">
> <TextBlock.Text>
> <Binding XPath="URL"/>
> </TextBlock.Text>
> </TextBlock>
> </StackPanel>
> </DataTemplate>
> </Window.Resources>
>
> <!-- write the data to the screen by binding the data template to a
> list box -->
> <StackPanel>
> <TextBlock FontSize="14" FontWeight="Bold" Margin="10">My
> Favorites</TextBlock>
> <ListBox x:Name="listbox1"
> BorderThickness="2"
> BorderBrush="White"
> Margin="10"
> ItemsSource="{Binding Source={StaticResource BookmarkData},
> XPath=Bookmark}"
> ItemTemplate="{StaticResource BookmarkDataTemplate}"/>
> </StackPanel>
>
> </Window>
>
> And see the code behind file :
>
> using System;
> using System.Windows;
> using System.Windows.Controls;
> using System.Windows.Data;
> using System.Windows.Documents;
> using System.Windows.Media;
> using System.Windows.Media.Imaging;
> using System.Windows.Shapes;
>
>
> namespace WindowsApplication1
> {
> /// <summary>
> /// Interaction logic for Window1.xaml
> /// </summary>
>
> public partial class Window1 : Window
> {
> //int [] values;
> public Window1()
> {
> // values=new int[10];
> InitializeComponent();
>
> // int i=listbox1.Items.Count;
>
> }
>
>
> }
> }
>
> Every time I uncomment this line // int i=listbox1.Items.Count;
> I get a baml exception ....
>
> Can anyone help me....
>



Old 03-06-2006   #3 (permalink)
Erno
Guest


 

Re: getting baml exception regularly...

And even then you have to be carefull. I found that many times the controls
haven't been rendered by then. So they do exist but ActualHeight and
ActualWidth might be 0 or NaN.

To force the controls to be drawn and sized at least once you can use
UpdateLayout()
(Don't call that too often!)

--
Erno
----
WPF tutorials: http://blogs.infosupport.com/ernow/articles/1878.aspx


"Sheva" <footballism@gmail.com> wrote in message
news:utdsGnSQGHA.3272@tk2msftngp13.phx.gbl...
>I think you can write an event handler which will hooks up to Window's
>Loaded event, and put that line of code into this event handler:
> for instance:
> in xaml, you do this:
> <Window Loaded="WindowLoadedEventHandler">
> and in code you do this:
> private void WindowLoadedEventHandler(Object sender, RoutedEventArgs e)
> {
> // int i=listbox1.Items.Count;
> }
>
> Sheva
> "madhur" <ahuja.madhur@gmail.com> wrote in message
> news:1141640410.933322.18340@u72g2000cwu.googlegroups.com...
>> Hello
>>
>> I am getting a baml exception every time a use a control inside my code
>> behind file. For ex consider this xaml code :
>>
>> <Window x:Class="WindowsApplication1.Window1"
>> xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
>> xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
>> Title="WindowsApplication1" Width="550" Height="400">
>> <Window.Resources>
>> <!-- define the XML data source as a resource -->
>> <XmlDataProvider x:Key="BookmarkData" Source="XMLFile1.xml"
>> XPath="/Favorites">
>>
>> </XmlDataProvider>
>>
>> <!-- create a data template to display the desired XML node values
>> -->
>> <DataTemplate x:Key="BookmarkDataTemplate">
>> <StackPanel Margin="5">
>> <TextBlock FontSize="12" FontWeight="Bold" Foreground="White">
>> <TextBlock.Text>
>> <Binding XPath="Title"/>
>> </TextBlock.Text>
>> </TextBlock>
>> <TextBlock FontSize="10" Foreground="LightGray">
>> <TextBlock.Text>
>> <Binding XPath="URL"/>
>> </TextBlock.Text>
>> </TextBlock>
>> </StackPanel>
>> </DataTemplate>
>> </Window.Resources>
>>
>> <!-- write the data to the screen by binding the data template to a
>> list box -->
>> <StackPanel>
>> <TextBlock FontSize="14" FontWeight="Bold" Margin="10">My
>> Favorites</TextBlock>
>> <ListBox x:Name="listbox1"
>> BorderThickness="2"
>> BorderBrush="White"
>> Margin="10"
>> ItemsSource="{Binding Source={StaticResource BookmarkData},
>> XPath=Bookmark}"
>> ItemTemplate="{StaticResource BookmarkDataTemplate}"/>
>> </StackPanel>
>>
>> </Window>
>>
>> And see the code behind file :
>>
>> using System;
>> using System.Windows;
>> using System.Windows.Controls;
>> using System.Windows.Data;
>> using System.Windows.Documents;
>> using System.Windows.Media;
>> using System.Windows.Media.Imaging;
>> using System.Windows.Shapes;
>>
>>
>> namespace WindowsApplication1
>> {
>> /// <summary>
>> /// Interaction logic for Window1.xaml
>> /// </summary>
>>
>> public partial class Window1 : Window
>> {
>> //int [] values;
>> public Window1()
>> {
>> // values=new int[10];
>> InitializeComponent();
>>
>> // int i=listbox1.Items.Count;
>>
>> }
>>
>>
>> }
>> }
>>
>> Every time I uncomment this line // int i=listbox1.Items.Count;
>> I get a baml exception ....
>>
>> Can anyone help me....
>>

>
>



Old 03-07-2006   #4 (permalink)
madhur
Guest


 

Re: getting baml exception regularly...

Thanks!!! that did the trick

Old 03-07-2006   #5 (permalink)
madhur
Guest


 

Re: getting baml exception regularly...

Thanks!!! that did the trick

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception stack is corrupt when catching and storing the exception Morten Herman Langkjaer .NET General 1 03-05-2008 02:11 AM
Vista Install Error: Exception Unknown Software Exception burntham77 Vista installation & setup 2 01-07-2008 01:39 PM
Vista regularly shuts down Charlie Vista General 1 10-02-2007 12:59 PM
Losing netowork regularly mister.jones Vista networking & sharing 34 06-18-2007 05:05 AM
baml parse error - November CTP wolfi Avalon 4 01-10-2006 03:52 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50