Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - getting baml exception regularly...

 
 
Old 03-06-2006   #1 (permalink)
madhur


 
 

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....


My System SpecsSystem Spec
Old 03-06-2006   #2 (permalink)
Sheva


 
 

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....
>



My System SpecsSystem Spec
Old 03-06-2006   #3 (permalink)
Erno


 
 

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....
>>

>
>



My System SpecsSystem Spec
Old 03-07-2006   #4 (permalink)
madhur


 
 

Re: getting baml exception regularly...

Thanks!!! that did the trick

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Exception stack is corrupt when catching and storing the exception .NET General
Vista Install Error: Exception Unknown Software Exception Vista installation & setup
Losing netowork regularly Vista networking & sharing
Vista Crashing regularly Vista General


Vista Forums 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 Ltd

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