.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

XamlParseException thrown when setting ListBox ItemTemplate.

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :WPF
What could be the cause of the issue described below and why is this exception thrown? Having created a DataTemplate like this: <DataTemplate x:Key="{x:Static controls:InternalResourceKeys.ListBoxItemTemplate}" DataType="{x:Type games:GameDefinitionBase}"> </DataTemplate>   I tried to use it as an ItemTemplate in a ListBox:   <ListBox x:Name="list_definitions" HorizontalContentAlignment="Stretch" SelectionMode="Single" ItemTemplate="{StaticResource {x:Static controls:InternalResourceKeys.ListBoxItemTemplate}}"> </ListBox>   where 'InternalResourceKeys' is the following:   static class InternalResourceKeys { static readonly object _listBoxItemTemplate = new object(); public static object ListBoxItemTemplate { get { return _listBoxItemTemplate; } } }   However, the resource lookup throws an exception (pasted at the end). The reason is most possibly this: {x:Static controls:InternalResourceKeys.ListBoxItemTemplate} used as DataTemplate key. What is a bit surprising is that I have already used InternalResourceKeys class as a storage for resource keys in the same application. Thus, the concept of resource keys being retrieved by a static property seems to work. NOTE: when I change all occurences of {x:Static controls:InternalR

View Complete Post

More Related Resource Links

setting scroll position for a ListBox


I have a ListBox control showing 10 rows.  I have 30 rows total in the listbox.  How do I programmatically adjust the scroll to show the last ten rows?

Some sources have suggested that I set the SelectedItem.  But I am already making selections (myListBox.Items[28].Selected = true, myListBox.Items[29].Selected = true, etc); the listbox scroll is positioned on Item[0] not the first selected item.  I have also tried setting myListBox.SelectedItem in addition to the multiple selection just mentioned but that does not have any affect either.


WPF, MVVM, Commands from buttons within a Listbox ItemTemplate? (code included)

I want to capture button clicks from within a list item row. Below I have tried to boil the problem down as much as I can. First, here is the xaml <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="test2.MainWindow" x:Name="Window" Title="MainWindow">  <Grid x:Name="LayoutRoot">  <ListView Margin="148,74,0,202" HorizontalAlignment="Left" ItemsSource="{Binding ListData}">   <ListView.View>    <GridView>     <GridViewColumn Header="Item" DisplayMemberBinding="{Binding ItemName}" />     <GridViewColumn Header="Options" Width="200" >      <GridViewColumn.CellTemplate>       <DataTemplate>        <StackPanel Orientation="Horizontal">         <Button Content="Reject" Height="20" Width="80" Margin="5,2" Command="{Binding Commands}" CommandParameter="RejectItem" /> 

Animate listbox items from ItemTemplate

I want to have a slide-in effect for listbox items, when it's first loaded. I'm using ItemTemplate for listbox items and I coule do the slide-in effect from within the template using RenderTransform and DocubleAnimation. but as the Listbox is vertualized, it does the effect everytime new page of data is loaded in listbox. What I want is to animate the visible items in listbox only when DataContext is changed the first time, like messages list in 'Windows Live Mail' thanks in advance.  

WPF: listbox ItemTemplate

We have a list box. Each item is a TextBlock. If the text too long, it will display as Ellipsis "..." at the end inside textblock. if the available list is too long, it will display a vertical scroll bar for the listbox. if the available list can be displayed in one page, the vertical scroll bar will not displayed. We have difine the <ListBox.ItemTemplate> <DataTemplate> <TextBlock Width="610" TextAlignment="Center" TextTrimming="CharacterEllipsis" Padding="3,0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Foreground="Black" Text="{Binding ProgramName}"/> </DataTemplate> </ListBox.ItemTemplate> The problem with this ItemTemplate, we have to define the textBlock's width in order to align the text content in the center and display the Ellipsis if text content is too long. However the real width is different with/without displaying the vertical scrool bar of listbox. So far we have to base on the vertical scroll bar displayed to decide the textblock's width. Is there someway, we can fix this problem? thx!  

page.setfocus(listbox.selecteditem) is not setting the focus if index > 820

Hi All, Does any one know the reason Why I am unable to setfocus to my list box if the index > 820 My list box contains 2000 items and the index is not  able to set the focus if the index > 820  

style not applied in ListBox.ItemTemplate


I have a resource dictionary with a style for Borders. The style has a TargetType but no x:Key. The dictionary also has a DataTemplate used as a ListBox.ItemTemplate. The DataTemplate has a Border in it. The Border style is not applied in the ListBox. I assumed that it would be. That is what I want.

What is the simplest way to get the Border style applied in the ListBox.ItemTemplate?


Find control TextBlock inside Listbox.ItemTemplate

Hello, I'm a big question, I have a XAML code, where it i
insert a TextBlock to the name "tbNomeHotel" but I can not
call it in C # code, for example: string = xxx tbNomeHotel.Text;

this only happens when the TextBlock is between the tags, and <ListBox.ItemTemplate> <DataTemplate>, which make the data come directly from the database and are displayed in a list.

below is the XAML code, where the bank's value is displayed in a ListBox, if the name of a hotel either!

I like to refer to the TextBlock component in my C # code, so I can use it as a parameter for other queries??

eg>> string xxx = tbNomeHotel.Text;



Name = <StackPanel "stkPanel" Orientation="Horizontal" Width="419">


ListBox tricky to set in a DataGrid/GridView

Listboxes are very tricky to set selected items in grid - there is no real nice way to do it. It would have been great if Microsoft included a property that accepts an array or comma separated values - or anything! But they only allow each item in the list to be selected individually. The way to do this in a grid is a bit messy, but it is fairly simple to implement. When a row is created (as per the event), select the items of the listbox as per the datagrid source data:

Working with DropDownList and ListBox Controls in ASP.NET

"In my application i am using dropdownlist to display all categories from a table. When the user clicks this control I display all records in that category. Category table also contains column called color.

I wanted display some categories in dropdown list different color and others in different color using ASP.NET."-Anonymous

Setting the default start page in godaddy hosting?


 How do you set the start page with godaddy hosting? I can see no way of doing this! You do not seem to have access to the IIS settings that allow you to change it!

Textbox in ItemTemplate inside Gridview, unable to get the value


Hi. I have a itemtemplate inside a gridview.

<asp:TemplateField HeaderText="Enter OTP">
                            <asp:Label ID="Label2" runat="server"
                                style="font-family: Arial, Helvetica, sans-serif; font-size: x-small"
                                Text="PIN Num:"></asp:Label>
                            &nbsp;<asp:TextBox ID="txtPIN" runat="server" Height="21px" Width="100px"></asp:TextBox>

Setting Screen Resolution



  I am developing a website in asp.net.How can i make my web pages view same in different screen resolutions.I am using 1024*768 resolution

Error while setting up application on Win7 using Visual Studio.NET 2003


Hi All,

Getting the below error while setting up application on Win 7 using visual studio.NET 2003.


cannot find the components for communiacting with the front page server extensions...


I understand by the error, i need to install Front page server extension, but not able to figure how to install using IIS 7.5.

I had XP machine with IIS 5.1, able to find the option.


Need your help in resolving this.




Persist data in a dynamically populated ListBox in a user control


Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)










My Click Function

Protected Void Button1_Click(object sender, EventArgs e)


       string strValue = listBox.SelectedValue



I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

Setting default localization



I ever thought that I can set a default localization if the users one (which is set in the browser) isn't available.

I've implemented my localresource files for localization. The start.aspx.resx contains all texts and elements for German use and the start.aspx.en.resx for English users. When I switch the language in the browser settings from German to English everything works fine and the english text is displayed. But when I switch to an other language which is not German or English, it takes defaulty the german resource files.

I've set

UICulture="auto:en-US" Culture="auto:en-US"

as well, but it didn't assume the .en resource file automatically. (For example when I enter the website and switch the browser language to French or Italian it should take the english resource files.)

Thanks and regards,

Advanced Basics: Setting Word Document Properties the Office 2007 Way


The last time I wrote this column (March 2006), I shared an application that allows you to update all the Microsoft® Word documents in a folder and its subfolders. Each time the application finds a document in the specified path, it updates the document properties to match those you specified in the application.

Ken Getz

MSDN Magazine June 2006

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend