![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | Re: getting baml exception regularly... Thanks!!! that did the trick ![]() |
My System Specs![]() |
| 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 | |||