Hi Peter, As far as I'm aware the ItemTemplate wont be used unless there is an actual data "item" to template. In other words an "item" in the ItemsSource (which you are not using) or an "item" in the Items collection.
If you are adding ListBoxItem directly to Items (a special case) then I'm not certain ItemTemplate will be used - you might need to set it manually on each ListBoxItem you create by using the ContentTemplate. This might get complicated quickly and Im not sure what you are winning. I know its annoying when people say "why are you doing it like that?" but might I suggest binding will work fine in this scenario? Prompting, parsing, validating, ensuring no duplicates can all still be done the way you specified... just at the end of it all add it to a ObservableCollection that is used *purely *for binding from the view. Bind your ListBox.ItemsSource to that collection, and the code you have above should just work (ListBoxItems will be created automatically to wrap the item). Cheers, Jack On Thu, Mar 3, 2011 at 2:54 PM, Peter Maddin <[email protected]>wrote: > I would like to be add ListBoxItems to a ListBox. > > I don’t want to bind the items to a data source. I need to have more > control than that. > > > > In fact what I need to do is to add a ListBoxItem I need to > > · Prompt user for a file. > > · Parse the file for a some data items (XML attributes) > > · If its ok, then create a new ListBoxItem containing some of > these attributes > > · Check that the same item has not been already added, if so > prompt the user to replace it. > > · If it does not already exist, add the ListBoxItem to the > ListBox. > > > > I would like to add nicely formatted ListBoxItems with a border that has > rounded corners etc. > > > > I am not sure how to create a new ListBoxItem. > > > > The XAML I am starting with is > > > > <ListBox Margin="10" Name="listBoxKeys"> > > <ListBox.ItemTemplate> > > <DataTemplate> > > <Border> > > <StackPanel Orientation="Horizontal"> > > > <!--<CheckBox IsChecked="{Binding Deleteable, Mode=TwoWay}" />--> > > <CheckBox IsChecked="False" /> > > <!--<Label Content="{Binding Name}" />--> > > <Label x:Name="Client" /> > > <Label x:Name="Generated" /> > > <Label x:Name="Description" /> > > </StackPanel> > > </Border> > > </DataTemplate> > > </ListBox.ItemTemplate> > > </ListBox> > > > > How do I create a new ListBoxItem that conforms to this template? > > > > Any help very much appreciated. > > > > *Regards Peter Maddin* > *Applications Development Officer* > *Path**West Laboratory Medicine WA* > *Phone : +618 6396 4285 > Mobile: 0414 240 307* > *E-Mail : [email protected]; [email protected]* > *The contents of this e-mail transmission outside of the WAGHS network are > intended solely for the named recipient's), may be confidential, and may be > privileged or otherwise protected from disclosure in the public interest. > The use, reproduction, disclosure or distribution of the contents of this > e-mail transmission by any person other than the named recipient(s) is > prohibited. If you are not a named recipient please notify the sender > immediately**.* > > > > > > _______________________________________________ > ozwpf mailing list > [email protected] > http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf > >
_______________________________________________ ozwpf mailing list [email protected] http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
