Search Results

Search found 369 results on 15 pages for 'observablecollection'.

Page 1/15 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How do I update ItemTemplate after scrambling ObservableCollection(Of ObservableCollection(Of object

    - by user342195
    I am learning vb.net, wpf and xaml with the help of sites like this one. The project I am currently working on is a 4 x 4 slide puzzle. I cannot get the buttons in the grid to scramble to start a new game when calling a new game event. Any help will be greatly appreciated. If no answer is can be provide, a good resource to research would help as well. Thank you for your time. XAML: <Window x:Class="SlidePuzzle" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Slide Puzzle" Height="391" Width="300" Name="wdw_SlidePuzzle"> <Window.Resources> <DataTemplate x:Key="DataTemp_PuzzleButtons"> <Button Content="{Binding C}" Height="50" Width="50" Margin="2" Visibility="{Binding V}"/> </DataTemplate> <DataTemplate x:Key="DataTemplate_PuzzleBoard"> <ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource DataTemp_PuzzleButtons}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemContainerStyle> <Style> <Setter Property="Canvas.Top" Value="{Binding Path=Y}" /> <Setter Property="Canvas.Left" Value="{Binding Path=X}" /> </Style> </ItemsControl.ItemContainerStyle> </ItemsControl> </DataTemplate> </Window.Resources> <DockPanel Name="dpanel_puzzle" LastChildFill="True"> <WrapPanel DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Center"> <Button Name="bttnNewGame" Content="New Game" MinWidth="75" Margin="4" Click="NewGame_Click"></Button> <Button Name="bttnSolveGame" Content="Solve" MinWidth="75" Margin="4"></Button> <Button Name="bttnExitGame" Content="Exit" MinWidth="75" Margin="4" Click="ExitGame_Click"></Button> </WrapPanel> <WrapPanel DockPanel.Dock="Bottom" Margin="5" HorizontalAlignment="Center"> <Label>Score:</Label> <TextBox Name="tb_Name" Width="50"></TextBox> </WrapPanel> <StackPanel Name="SlidePuzzlePnl" HorizontalAlignment="Center" VerticalAlignment="Center" Height="206" Width="206" > <ItemsControl x:Name="lst" ItemTemplate="{DynamicResource DataTemplate_PuzzleBoard}"/> </StackPanel> </DockPanel> VB: Imports System.Collections.ObjectModel Class SlidePuzzle Dim puzzleColl As New ObservableCollection(Of ObservableCollection(Of SlidePuzzleBttn)) Dim puzzleArr(3, 3) As Integer Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded For i As Integer = 0 To 3 puzzleColl.Add(New ObservableCollection(Of SlidePuzzleBttn)) For j As Integer = 0 To 3 puzzleArr(i, j) = (i * 4) + (j + 1) puzzleColl(i).Add(New SlidePuzzleBttn((i * 4) + (j + 1))) puzzleColl(i)(j).X = j * 52 puzzleColl(i)(j).Y = i * 52 Next Next lst.ItemsSource = puzzleColl End Sub Private Sub NewGame_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim rnd As New Random Dim ri, rj As Integer Dim temp As Integer For i As Integer = 0 To 3 For j As Integer = 0 To 3 ri = rnd.Next(0, 3) rj = rnd.Next(0, 3) temp = puzzleArr(ri, rj) puzzleArr(ri, rj) = puzzleArr(i, j) puzzleArr(i, j) = temp puzzleColl(i)(j).X = j * 52 puzzleColl(i)(j).Y = i * 52 puzzleColl(i)(j).C = puzzleArr(i, j) Next Next End Sub End Class Public Class SlidePuzzleBttn Inherits DependencyObject Private _c As Integer Private _x As Integer Private _y As Integer Private _v As String Public Shared ReadOnly ContentProperty As DependencyProperty = DependencyProperty.RegisterAttached("_c", GetType(String), GetType(SlidePuzzleBttn), New UIPropertyMetadata("")) Public Sub New() _c = 0 _x = 0 _y = 0 _v = SetV(_c) End Sub Public Sub New(ByVal cVal As Integer) _c = cVal _x = 0 _y = 0 _v = SetV(cVal) End Sub Public Property C() As Integer Get Return _c End Get Set(ByVal value As Integer) _c = value End Set End Property Public Property X() As Integer Get Return _x End Get Set(ByVal value As Integer) _x = value End Set End Property Public Property Y() As Integer Get Return _y End Get Set(ByVal value As Integer) _y = value End Set End Property Public Property V() As String Get Return _v End Get Set(ByVal value As String) _v = value End Set End Property Private Function SetV(ByRef cVal As Integer) As String If cVal = 16 Then Return "Hidden" Else Return "Visible" End If End Function End Class

    Read the article

  • How to track deleted self-tracking entities in ObservableCollection without memory leaks

    - by Yannick M.
    In our multi-tier business application we have ObservableCollections of Self-Tracking Entities that are returned from service calls. The idea is we want to be able to get entities, add, update and remove them from the collection client side, and then send these changes to the server side, where they will be persisted to the database. Self-Tracking Entities, as their name might suggest, track their state themselves. When a new STE is created, it has the Added state, when you modify a property, it sets the Modified state, it can also have Deleted state but this state is not set when the entity is removed from an ObservableCollection (obviously). If you want this behavior you need to code it yourself. In my current implementation, when an entity is removed from the ObservableCollection, I keep it in a shadow collection, so that when the ObservableCollection is sent back to the server, I can send the deleted items along, so Entity Framework knows to delete them. Something along the lines of: protected IDictionary<int, IList> DeletedCollections = new Dictionary<int, IList>(); protected void SubscribeDeletionHandler<TEntity>(ObservableCollection<TEntity> collection) { var deletedEntities = new List<TEntity>(); DeletedCollections[collection.GetHashCode()] = deletedEntities; collection.CollectionChanged += (o, a) => { if (a.OldItems != null) { deletedEntities.AddRange(a.OldItems.Cast<TEntity>()); } }; } Now if the user decides to save his changes to the server, I can get the list of removed items, and send them along: ObservableCollection<Customer> customers = MyServiceProxy.GetCustomers(); customers.RemoveAt(0); MyServiceProxy.UpdateCustomers(customers); At this point the UpdateCustomers method will verify my shadow collection if any items were removed, and send them along to the server side. This approach works fine, until you start to think about the life-cycle these shadow collections. Basically, when the ObservableCollection is garbage collected there is no way of knowing that we need to remove the shadow collection from our dictionary. I came up with some complicated solution that basically does manual memory management in this case. I keep a WeakReference to the ObservableCollection and every few seconds I check to see if the reference is inactive, in which case I remove the shadow collection. But this seems like a terrible solution... I hope the collective genius of StackOverflow can shed light on a better solution. Thanks!

    Read the article

  • ObservableCollection is not updating Multibinding in C# WPF

    - by Decept
    I have a TreeView that creates all its items from databound ObservableCollections. I have a hierarchy of GameNode objects, each object has two ObservableCollections. One collections has EntityAttrib objects and the other have GameNode objects. You could say that the GameNode object represents folders and EntityAttrib represents files. To display both attrib and GameNodes in the same TreeView I use Multibinding. This all works fine in startup, but when I add a new GameNode somewhere in the hierarchy the TreeView is not updated. I set a breakpoint in my converter method but it's not called when adding a new GameNode. It seems that the ObservableCollection is not notifying the MultiBinding of the change. If I comment out the MultiBinding and only bind the GameNode collection it works as expected. XAML: <HierarchicalDataTemplate DataType="{x:Type local:GameNode}"> <HierarchicalDataTemplate.ItemsSource> <MultiBinding Converter="{StaticResource combineConverter}"> <Binding Path="Attributes" /> <Binding Path="ChildNodes" /> </MultiBinding> </HierarchicalDataTemplate.ItemsSource> <TextBlock Text="{Binding Path=Name}" ContextMenu="{StaticResource EntityCtxMenu}"/> </HierarchicalDataTemplate> C#: public class GameNode { string mName; public string Name { get { return mName; } set { mName = value; } } GameNodeList mChildNodes = new GameNodeList(); public GameNodeList ChildNodes { get { return mChildNodes; } set { mChildNodes = value; } } ObservableCollection<EntityAttrib> mAttributes = new ObservableCollection<EntityAttrib>(); public ObservableCollection<EntityAttrib> Attributes { get { return mAttributes; } set { mAttributes = value; } } } GameNodeList is a subclassed ObservableCollection

    Read the article

  • ObservableCollection and CollectionChanged Event

    - by wpfwannabe
    Why does the collectionchanged event not fire in the following code, yet I can see the new instance of InventoryBTO I add to the ObservableCollection? private ObservableCollection<InventoryBTO> _inventoryRecords; public ObservableCollection<InventoryBTO> InventoryRecords { get { return _inventoryRecords; } set { _inventoryRecords = value; } } private InventoryBTO _selectedRecord; public InventoryBTO SelectedRecord { get { return _selectedRecord; } set { if (_selectedRecord != value) { _selectedRecord = value; OnPropertyChanged(new PropertyChangedEventArgs("SelectedRecord")); } } } public InventoryViewModel() { if (_inventoryRecords == null) { InventoryRecords = new ObservableCollection<InventoryBTO>(); this.InventoryRecords.CollectionChanged += new NotifyCollectionChangedEventHandler(InventoryRecords_CollectionChanged); } _inventoryRecords = InventoryListBTO.GetAllInventoryRecords(); } void InventoryRecords_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { }

    Read the article

  • difference between ObservableCollection and BindingList

    - by Azhar
    I want to know the difference between ObservableCollection and BindingList because I've used both to notify for any add/delete change in Source, but I actually do not know when to prefer one over the other. Why would I choose one of the following over the other? ObservableCollection<Employee> lstEmp = new ObservableCollection<Employee>(); or BindingList<Employee> lstEmp = new BindingList<Employee>();

    Read the article

  • WPF ObservableCollection in xaml

    - by Cloverness
    Hi, I have created an ObservableCollection in the code behind of a user control. It is created when the window loads: private void UserControl_Loaded(object sender, RoutedEventArgs e) { Entities db = new Entities(); ObservableCollection<Image> _imageCollection = new ObservableCollection<Image>(); IEnumerable<library> libraryQuery = from c in db.ElectricalLibraries select c; foreach (ElectricalLibrary c in libraryQuery) { Image finalImage = new Image(); finalImage.Width = 80; BitmapImage logo = new BitmapImage(); logo.BeginInit(); logo.UriSource = new Uri(c.url); logo.EndInit(); finalImage.Source = logo; _imageCollection.Add(finalImage); } } I need to get the ObservableCollection of images which are created based on the url saved in a database. But I need a ListView or other ItemsControl to bind to it in XAML file like this: But I can't figure it out how to pass the ObservableCollection to the ItemsSource of that control. I tried to create a class and then create an instance of a class in xaml file but it did not work. Should I create a static resource somehow Any help will be greatly appreciated.

    Read the article

  • Binding TabControl ItemsSource to an ObservableCollection of ViewModels causes content to refresh on

    - by Brent
    I'm creating an WPF application using the MVVM framework, and I've adopted several features from Josh Smith's article on MVVM here... Most importantly, I'm binding a TabControl to an ObservableCollection of ViewModels. This means that am using a tabbed MDI interface that displays a UserControl as the content of a TabItem. The issue I'm seeing in my application is that when I have several tabs and I flip back and forth between tabs, the content is being refersh each time I change tabs. If you download Josh Smith's source code, you'll see that his app has the same problem. For example, click on the "View All Customers" button and scroll down to the bottom the ListView. Next click on the "Create New Customer" button. When you switch back to the All Customer view you'll notice that the ListView scrolls back to the top. If you switch back to the New Customer tab and place your cursor in one of the TextBoxes, then switch to All Customers tab and back, you'll notice that the cursor is now gone. I imagine that this is because I'm using an ObservableCollection, but I can't be sure. Is there any way to prevent the tab's content from refreshing when it receives the focus? EDIT: I found my problem when I ran the profiler on my application. I'm defining a DataTemplate for my ViewModels so it knows how to render the ViewModel when it is displayed in the tab... like so: <DataTemplate DataType="{x:Type vm:CustomerViewModel}"> <vw:CustomerView/> </DataTemplate> So whenever I switch to a different tab, it has to re-create the ViewModel again. I fixed it temporarily by changing my ObservableCollection of ViewModels to an ObservableCollection of UserControls. However, I would really still like to use DataTemplates if possible. Is there a way to make a DataTemplate work?

    Read the article

  • Why does implementing ObservableCollection crash my silverlight application?

    - by Sudeep
    Hi, I have a combobox whose ItemsSource property is bound to an ObservableCollection property and its SelectedIndex property is bound to an integer property respectively. <ComboBox Name="cmbDealt" ItemsSource="{Binding Path=DealList, Mode=TwoWay}" SelectedIndex="{Binding Mode=TwoWay, Path=DealIndex}"></ComboBox> <CheckBox IsChecked="{Binding Mode=TwoWay, Path=SomeCondition}" Content="Some Condition"></CheckBox> My data structure looks like private ObservableCollection<string> m_DealList = null; private int m_DealIndex = 0; private bool m_SomeCondition = false; public ObservableCollection<string> DealList { get { if (m_DealList == null) m_DealList = new ObservableCollection<string>(); else m_DealList.Clear(); if (m_SomeCondition) { m_DealList.Add("ABC"); m_DealList.Add("DEF"); } else { m_DealList.Add("UVW"); m_DealList.Add("XYZ"); } return m_DealList; } } public int DealIndex { get { return m_DealIndex; } set { if (value != -1) { m_DealIndex = value; } } } public bool SomeCondition { get { return m_SomeCondition; } set { m_SomeCondition = value; OnPropertyChanged("DealList"); OnPropertyChanged("DealIndex"); } } Now the application loads successfully. However, when the user changes the SelectedIndex of the ComboBox to 1 from 0 and then checks the checkbox (so as to call the "DealIndex" property changed event), the application crashes. I am not sure why this could be happening. Can someone shed some light and propose a solution? TIA... Sudeep

    Read the article

  • wpf observableCollection

    - by Asha
    I have an ObservableCollection which is dataContext for my treeview when I try to remove an Item from ObservableCollection I will get an error that Object reference not set to an instance of an object . can you please tell me why this error is happening and what is the solution thanks EDIT 1: The code is something like : class MyClass : INotifyPropertyChanged { //my class code here } public partial class UC_myUserControl : UserControl { private ObservableCollection<MyClass> myCollection = new ObservableCollection<MyClass>(); private void UserControl_Loaded(object sender, RoutedEventArgs e) { myCollection.add(new myClass); myTreeView.DataContext = myCollection ; } private void deleteItem() { myCollection.RemoveAt(0); //after removing I get error Which I guess should be something related //to interface update but I don't know how can I solve it } } Exception Detail : System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="PresentationFramework" EDIT 3: I have a style which is for my treeitem to keep the treeitems expanded <Style TargetType="TreeViewItem"> <Setter Property="IsExpanded" Value="True" /> </Style> and with commenting this part I wont get any error !!! Now I want to change my question to why having this style is causing error ?

    Read the article

  • When Clearing an ObservableCollection, There are No Items in e.OldItems

    - by cplotts
    I have something here that is really catching me off guard. I have an ObservableCollection of T that is filled with items. I also have an event handler attached to the CollectionChanged event. When you Clear the collection it causes an CollectionChanged event with e.Action set to NotifyCollectionChangedAction.Reset. Ok, that's normal. But what is weird is that neither e.OldItems or e.NewItems has anything in it. I would expect e.OldItems to be filled with all items that were removed from the collection. Has anyone else seen this? And if so, how have they gotten around it? Some background: I am using the CollectionChanged event to attach and detach from another event and thus if I don't get any items in e.OldItems ... I won't be able to detach from that event. CLARIFICATION: I do know that the documentation doesn't outright state that it has to behave this way. But for every other action, it is notifying me of what it has done. So, my assumption is that it would tell me ... in the case of Clear/Reset as well. Below is the sample code if you wish to reproduce it yourself. First off the xaml: <Window x:Class="ObservableCollection.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" > <StackPanel> <Button x:Name="addButton" Content="Add" Width="100" Height="25" Margin="10" Click="addButton_Click"/> <Button x:Name="moveButton" Content="Move" Width="100" Height="25" Margin="10" Click="moveButton_Click"/> <Button x:Name="removeButton" Content="Remove" Width="100" Height="25" Margin="10" Click="removeButton_Click"/> <Button x:Name="replaceButton" Content="Replace" Width="100" Height="25" Margin="10" Click="replaceButton_Click"/> <Button x:Name="resetButton" Content="Reset" Width="100" Height="25" Margin="10" Click="resetButton_Click"/> </StackPanel> </Window> Next, the code behind: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Collections.ObjectModel; namespace ObservableCollection { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public Window1() { InitializeComponent(); _integerObservableCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(_integerObservableCollection_CollectionChanged); } private void _integerObservableCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Move: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Replace: break; case System.Collections.Specialized.NotifyCollectionChangedAction.Reset: break; default: break; } } private void addButton_Click(object sender, RoutedEventArgs e) { _integerObservableCollection.Add(25); } private void moveButton_Click(object sender, RoutedEventArgs e) { _integerObservableCollection.Move(0, 19); } private void removeButton_Click(object sender, RoutedEventArgs e) { _integerObservableCollection.RemoveAt(0); } private void replaceButton_Click(object sender, RoutedEventArgs e) { _integerObservableCollection[0] = 50; } private void resetButton_Click(object sender, RoutedEventArgs e) { _integerObservableCollection.Clear(); } private ObservableCollection<int> _integerObservableCollection = new ObservableCollection<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; } }

    Read the article

  • Databinding to ObservableCollection in a different UserControl?

    - by Dave
    Question re-written on 2010-03-24 I have two UserControls, where one is a dialog that has a TabControl, and the other is one that appears within said TabControl. I'll just call them CandyDialog and CandyNameViewer for simplicity's sake. There's also a data management class called Tracker that manages information storage, which for all intents and purposes just exposes a public property that is an ObservableCollection. I display the CandyNameViewer in CandyDialog via code behind, like this: private void CandyDialog_Loaded( object sender, RoutedEventArgs e) { _candyviewer = new CandyViewer(); _candyviewer.DataContext = _tracker; candy_tab.Content = _candyviewer; } The CandyViewer's XAML looks like this (edited for kaxaml): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <DataTemplate x:Key="CandyItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition Width="150"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Text="{Binding CandyName}" Margin="3"></TextBox> <!-- just binding to DataContext ends up using InventoryItem as parent, so we need to get to the UserControl --> <ComboBox Grid.Column="1" SelectedItem="{Binding SelectedCandy, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CandyNames}" Margin="3"></ComboBox> </Grid> </DataTemplate> </Page.Resources> <Grid> <ListBox DockPanel.Dock="Top" ItemsSource="{Binding CandyBoxContents, Mode=TwoWay}" ItemTemplate="{StaticResource CandyItemTemplate}" /> </Grid> </Page> Now everything works fine when the controls are loaded. As long as CandyNames is populated first, and then the consumer UserControl is displayed, all of the names are there. I obviously don't get any errors in the Output Window or anything like that. The issue I have is that when the ObservableCollection is modified from the model, those changes are not reflected in the consumer UserControl! I've never had this problem before; all of my previous uses of ObservableCollection updated fine, although in those cases I wasn't databinding across assemblies. Although I am currently only adding and removing candy names to/from the ObservableCollection, at a later date I will likely also allow renaming from the model side. Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

    Read the article

  • problem binding ListBox on ObservableCollection<T>

    - by Fabian
    Hello, I have a strange "problem". Could someone explain me why : If I have in an ObservableCollection, twice (or more time) an item with the same value, then the selections of those values in the ListBox won't work properly ? In fact, what the ListBox is doing when I click on an item(Even in single item selection) : It selects the first item from the ObservableCollection collection with a matching value. so in the case if multiple items with same value are in the collection, then only the first one will be selected !

    Read the article

  • Get the string "System.Collections.ObjectModel.ObservableCollection" from a Type (System.type) containing a generic ObservableCollection?

    - by Guillaume Cogranne
    I got a Type whose FullName is (if this helps) : "System.Collections.ObjectModel.ObservableCollection`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" From that Type, I'd like to get "System.Collections.ObjectModel.ObservableCollection" as a string but I'd like to do it "cleanly", which means, without spliting the string with the char '`'. I think the strategy is to get something like a Type or something else whose FullName will be "System.Collections.ObjectModel.ObservableCollection" but I really don't manage to do it :/

    Read the article

  • PropertyChanged Event of ViewModel in ObservableCollection

    - by developer
    Hi All, I have a observable collection of viewmodel objects. How can I subscribe to the Property Changed event of each view model in my collection as they are created and track which ones have been changed, so that I can updated them to my database. //This is how I load my data public static ObservableCollection<ProgramViewModel> program { get; set; } program = new ObservableCollection<ProgramViewModel>(); foreach (DomainObject obj in res.ResultSet) { Program prg = (Program)obj; program.Add(new ProgramViewModel(prg)); }

    Read the article

  • WPF - databinding ObservableCollection CollectionChanged event?

    - by e0eight
    Hi, I have an observable collection implemented in my user control which indicates states of a device. Based on the collection change, the user control is to trigger animations(subscribe to collectionchanged event). The observable collection is implemented as a dependency property. In the application, I data bind the device states to the user control observableCollection using one-way databinding. When a new state is added in the application, I can see the ObservableCollection in the user control is updated. However, the CollectionChanged event never got fired, so no animations. Does anyone has an idea why this is so? Thank you in advance.

    Read the article

  • Binding TabControl ItemsSource to an ObservableCollection causes content to refresh on focus

    - by Brent
    I'm creating an WPF application using the MVVM framework, and I've adopted several features from Josh Smith's article on MVVM here... Most importantly, I'm binding a TabControl to an ObservableCollection of ViewModels. This means that am using a tabbed MDI interface that displays a UserControl as the content of a TabItem. The issue I'm seeing in my application is that when I have several tabs and I flip back and forth between tabs, the content is being refersh each time I change tabs. If you download Josh Smith's source code, you'll see that his app has the same problem. For example, click on the "View All Customers" button and scroll down to the bottom the ListView. Next click on the "Create New Customer" button. When you switch back to the All Customer view you'll notice that the ListView scrolls back to the top. If you switch back to the New Customer tab and place your cursor in one of the TextBoxes, then switch to All Customers tab and back, you'll notice that the cursor is now gone. I imagine that this is because I'm using an ObservableCollection, but I can't be sure. Is there any way to prevent the tab's content from refreshing when it receives the focus?

    Read the article

  • WPF: Binding to ObservableCollection in ControlTemplate is not updated

    - by Julian Lettner
    I created a ControlTemplate for my custom control MyControl. MyControl derives from System.Windows.Controls.Control and defines the following property public ObservableCollection<MyControl> Children{ get; protected set; }. To display the nested child controls I am using an ItemsControl (StackPanel) which is surrounded by a GroupBox. If there are no child controls, I want to hide the GroupBox. Everything works fine on application startup: The group box and child controls are shown if the Children property initially contained at least one element. In the other case it is hidden. The problem starts when the user adds a child control to an empty collection. The GroupBox's visibility is still collapsed. The same problem occurs when the last child control is removed from the collection. The GroupBox is still visible. Another symptom is that the HideEmptyEnumerationConverter converter does not get called. Adding/removing child controls to non empty collections works as expected. Whats wrong with the following binding? Obviously it works once but does not get updated, although the collection I am binding to is of type ObservableCollection. <!-- Converter for hiding empty enumerations --> <Common:HideEmptyEnumerationConverter x:Key="hideEmptyEnumerationConverter"/> <!--- ... ---> <ControlTemplate TargetType="{x:Type MyControl}"> <!-- ... other stuff that works ... --> <!-- Child components --> <GroupBox Header="Children" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Children, Converter={StaticResource hideEmptyEnumerationConverter}}"> <ItemsControl ItemsSource="{TemplateBinding Children}"/> </GroupBox> </ControlTemplate> . [ValueConversion(typeof (IEnumerable), typeof (Visibility))] public class HideEmptyEnumerationConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { int itemCount = ((IEnumerable) value).Cast<object>().Count(); return itemCount == 0 ? Visibility.Collapsed : Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } #endregion } Another, more general question: How do you guys debug bindings? Found this (http://bea.stollnitz.com/blog/?p=52) but still I find it very hard to do. I am glad for any help or suggestion.

    Read the article

  • Using ObservableCollection in ASP.NET

    - by Andrey
    I need to use functionality that ObservableCollection provides, in my asp.net app. My only concern is that this class is a part of WindowsBase assembly and I'm not sure if it's a good idea to include a windows assembly in a web project. Any ideas/comments? Thanks!

    Read the article

  • ObservableCollection Implementation

    - by wpfwannabe
    I know I am missing something obvious but I can't seem to implement ObservableCollection in my class below. IE it won't show up in intellsense. Can someone please let me know what I am missing. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Collections.ObjectModel; using System.Reflection; using System.ComponentModel; namespace MyBTOList { public class InventoryListBTO : List<InventoryBTO> { /// <summary> /// Get all inventory records from local database /// </summary> /// <returns></returns> public static InventoryListBTO GetAllInventoryRecords() { return GetInventoryListBO(Inventory.GetAllInventoryRecordsDb()); } } public class InventoryBTO : INotifyPropertyChanged { }

    Read the article

  • BeginInvoke on ObservableCollection not immediate.

    - by Padu Merloti
    In my code I subscribe to an event that happens on a different thread. Every time this event happens, I receive an string that is posted to the observable collection: Dispatcher currentDispatcher = Dispatcher.CurrentDispatcher; var SerialLog = new ObservableCollection<string>(); private void hitStation_RawCommandSent(object sender, StringEventArgs e) { string command = e.Value.Replace("\r\n", ""); Action dispatchAction = () => SerialLog.Add(command); currentDispatcher.BeginInvoke(dispatchAction, DispatcherPriority.Render); } The code below is in my view model (could be in the code behind, it doesn't matter in this case). When I call "hitstation.PrepareHit", the event above gets called a couple times, then I wait and call "hitStation.HitBall", and the event above gets called a couple more times. private void HitBall() { try { try { Mouse.OverrideCursor = Cursors.Wait; //prepare hit hitStation.PrepareHit(hitSpeed); Thread.Wait(1000); PlayWarning(); //hit hitStation.HitBall(hitSpeed); } catch (TimeoutException ex) { MessageBox.Show("Timeout hitting ball: " + ex.Message); } } finally { Mouse.OverrideCursor = null; } } The problem I'm having is that the ListBox that is bound to my SerialLog gets updated only when the HitBall method finishes. I was expecting seeing a bunch of updates from the PrepareHit, a pause and then a bunch more updates from the HitBall. I've tried a couple of DispatcherPriority arguments, but they don't seem to have any effect.

    Read the article

  • MVVM/WPF: Using a ObservableCollection<T> as a list in a domain model, is that good/bad ?

    - by msfanboy
    I have aggregated models like Customer:Order:Product. As my View is bound to the BillingViewModel which has a Property Customers of type ObservableCollection and ONE customer in this collection has a "list" of orders named ObservableCollection and ONE order in this collection has a "list" of products named ObservableCollection Well I need the ObservableCollection`s for databinding but should a domain model really have a ObservableCollection ? normally it has a List or IEnumerable ! Is this bad habit or having side effects?

    Read the article

  • WPF - Binding an ObservableCollection Dependency Property within a UserControl

    - by John
    I have a control class DragGrid : Grid { ... } which inherits from the original grid and enables dragging and resizing its child elements. I need to bind a custom DP named WorkItemsProperty to an observable collection of type WorkItem (implements INotifyPropertyChanged). Each element in the grid is bound to a collection item. Whenever the user adds a new item dynamically at runtime (the items cannot be declared in XAML!), or deletes an item from that collection, the WorkItems DP on the DragGrid should be updated, and the children in the grid (where each child represents a WorkItem collection item). My question is how does the DP notify the control about which child element in the grid must be removed, changed ('change' means user dragged an element, or resized it with the mouse) or added, and how would I identify which one of the existing children is the one that needs to be deleted or changed. I understand that this is where the DependencyPropertyChangedCallback comes in. But that only gets called when the DP property is set anew, not when something inside the collection changes (like add, remove item). So in the end, does the DragGrid control somehow need to subscribe to the CollectionChanged event? At what point would I hook up the event handler for that?

    Read the article

  • [C#/WPF] Combo box Item source = ObservableCollection & I need a '-None-' dummy entry at the top

    - by James
    I have a combo box using an observable collection as a datasource and I want a "dummy" value of "None" as the first item in the box as it controls filters against other data sources. Other databound objects also use the same observable collection so adding a "None" value directly to the datasource is not possible as I dont want, for example, my datagrids having a "none" in them. Also I'd rather avoid filters to just remove the "none" value for those that do not use it, as I'd like the observable collection to direclty reflect the database data; if at all possible. I'd also like to avoid having one observable collection per databound control. What I'm really after is a was to put a, non data bound, first entry into a combobox while also having the item source pointed at an obervable collection. Thanks

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >