Search Results

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

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

  • Observable Collections

    - by SGWellens
    I didn't think it was possible, but .NET surprised me yet again with a cool feature I never knew existed: The ObservableCollection. This became available in .NET 3.0. In essence, an ObservableCollection is a collection with an event you can connect to. The event fires when the collection changes. As usual, working with the .NET classes is so ridiculously easy, it feels like cheating. The following is small test program to illustrate how the ObservableCollection works. To start, create an ObservableCollection and then store it in the Session object so it will persist between page post backs. I also added the code to pull it out of Session state when there is a page post back:   public partial class _Default : System.Web.UI.Page{    public ObservableCollection<int> MyInts;     // ---- Page_Load ------------------------------     protected void Page_Load(object sender, EventArgs e)    {        if (IsPostBack == false)        {            MyInts = new ObservableCollection<int>();            MyInts.CollectionChanged += CollectionChangedHandler;             Session["MyInts"] = MyInts;  // store for use between postbacks        }        else        {            MyInts = Session["MyInts"] as ObservableCollection<int>;        }    } Here's the event handler I hooked up to the ObservableCollection, it writes status strings to a ListBox. Note: The event handler fires in a different thread than the IIS process thread.     // ---- CollectionChangedHandler -----------------------------------    //    // Something changed in the Observable collection     public void CollectionChangedHandler(object sender, NotifyCollectionChangedEventArgs e)    {        // need to dig around to get the current page and control to write to:        // (because this is in a separate thread)        Page CurrentPage = System.Web.HttpContext.Current.Handler as Page;        ListBox LB = CurrentPage.FindControl("ListBoxHistory") as ListBox;         switch (e.Action)        {            case NotifyCollectionChangedAction.Add:                LB.Items.Add("Add: " + e.NewItems[0]);                               break;             case NotifyCollectionChangedAction.Remove:                LB.Items.Add("Remove: " + e.OldItems[0]);                break;             case NotifyCollectionChangedAction.Reset:                LB.Items.Add("Reset: ");                break;             default:                LB.Items.Add(e.Action.ToString());                break;                     }    }  Next, add some buttons and code to exercise the ObservableCollection:     <br />    <asp:Button ID="ButtonAdd" runat="server" Text="Add" OnClick="ButtonAdd_Click" />    <asp:Button ID="ButtonRemove" runat="server" Text="Remove" OnClick="ButtonRemove_Click" />    <asp:Button ID="ButtonReset" runat="server" Text="Reset" OnClick="ButtonReset_Click" />    <asp:Button ID="ButtonList" runat="server" Text="List" OnClick="ButtonList_Click" />    <br />    <asp:TextBox ID="TextBoxInt" runat="server" Width="51px"></asp:TextBox>    <br />    <asp:ListBox ID="ListBoxHistory" runat="server" Height="255px" Width="195px">    </asp:ListBox>    // ---- Add Button --------------------------------------     protected void ButtonAdd_Click(object sender, EventArgs e)    {        int Temp;        if (int.TryParse(TextBoxInt.Text, out Temp) == true)            MyInts.Add(Temp);    }     // ---- Remove Button --------------------------------------     protected void ButtonRemove_Click(object sender, EventArgs e)    {        int Temp;        if (int.TryParse(TextBoxInt.Text, out Temp) == true)            MyInts.Remove(Temp);    }     // ---- Button Reset -----------------------------------     protected void ButtonReset_Click(object sender, EventArgs e)    {        MyInts.Clear();    }     // ---- Button List --------------------------------------     protected void ButtonList_Click(object sender, EventArgs e)    {        ListBoxHistory.Items.Add("MyInts:");        foreach (int i in MyInts)        {            // a bit of tweaking to get the text to be indented            ListItem LI = new ListItem("&nbsp;&nbsp;" + i.ToString());            LI.Text = Server.HtmlDecode(LI.Text);            ListBoxHistory.Items.Add(LI);        }    } Here's what it looks like after entering some numbers and clicking some buttons: An interesting note is that I had to use: System.Web.HttpContext.Current.Response to write to a control on the page. As mentioned earlier, this implies that the notification event is in a thread separate from the IIS thread. Another interesting note: From the online help: Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe What does that mean to Asp.Net developers? If you are going to share an ObservableCollection among different sessions, you'd better make it a static object. I hope someone finds this useful. Steve Wellens

    Read the article

  • PropertyChanged Event of 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. List<DomainObject> objectsToSave = new List<DomainObject>(); foreach (Test val in dirtyObjs) { objectsToSave.AddRange(val.GetObjectsToSave()); } //DB changes bool saveSucceeded = DataServices.SaveMultiple(objectsToSave);

    Read the article

  • Databinding to ObservableCollection in a different UserControl - how to preserve current selections?

    - by Dave
    Scope of question expanded on 2010-03-25 I ended up figuring out my problem, but here's a new problem that came up as a result of solving the original question, because I want to be able to award the bounty to someone!!! Once I figured out my problem, I soon found out that when the ObservableCollection updates, the databound ComboBox has its contents repopulated, but most of the selections have been blanked out. I assume that in this case, MVVM is going to make it difficult for me to remember the last selected item. I have an idea, but it seems a little nasty. I'll award the bounty to whomever comes up with a nice solution for this! 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

  • Why isn't it possible to update an ObservableCollection from a different thread?

    - by MainMa
    In a multi-threaded WPF application, it is not possible to update an ObservableCollection from a thread other than WPF window thread. I know there are workarounds, so my question is not how to avoid the "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread" exception. My question is, why there is such an exception? Why wasn't it possible to allow collection updates from any thread? Personally, I don't see any reason to block UI update when ObservableCollection is changed from other threads. If two threads (including parallel ones) are accessing the same object, one listening for changes of object properties through events, the other one doing changes, it will always work, at least if locks are used properly. So, what are the reasons?

    Read the article

  • How can I make a read-only ObservableCollection property?

    - by thrag
    I'd like to expose a property on a view model that contains a list of objects (from database). I need this collection to be read-only. That is, I want to prevent Add/Remove, etc. But allow the foreach and indexers to work. My intent is to declare a private field holding the editable collection and reference it with a read-only Public Property. As follows public ObservableCollection<foo> CollectionOfFoo { get { return _CollectionOfFoo; } } However, that syntax just prevents changing the reference to the collection. It doesn't prevent add/remove, etc. What is the right way to accomplish this?

    Read the article

  • Binding to an ObservableCollection attached property.

    - by bwreichle
    I want to create an attached property of type ObservableCollection<Notification> and bind it to a property of the same type on the DataContext. Currently I have: internal static class Squiggle { public static readonly DependencyProperty NotificationsProperty = DependencyProperty.RegisterAttached( "Notifications", typeof(ObservableCollection<Notification>), typeof(TextBox), new FrameworkPropertyMetadata(null, NotificationsPropertyChanged, CoerceNotificationsPropertyValue)); public static void SetNotifications(TextBox textBox, ObservableCollection<Notification> value) { textBox.SetValue(NotificationsProperty, value); } public static ObservableCollection<Notification> GetNotifications(TextBox textBox) { return (ObservableCollection<Notification>)textBox.GetValue(NotificationsProperty); } ... } With the following XAML: <TextBox x:Name="configTextBox" Text="{Binding Path=ConfigText, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" AcceptsTab="True" local:Squiggle.Notifications="{Binding Path=Notifications}" /> Unfortunatly, when I actually run this I get an exception stating: A 'Binding' cannot be used within a 'TextBox' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. This only seems to be a problem when the attached property is of type ObservableCollection so it seems like WPF is trying to do something magical when binding properties of this type and getting confused in the process. Anyone know what I need to do to make it work?

    Read the article

  • C# - Convert Implict Type to ObservableCollection

    - by user70192
    Hello, I have a LINQ statement that returns an implicit type. I need to get this type to be an ObservableCollection in my Silverlight 3 application. The ObservableCollection constructor in Silverlight 3 only provides an empty constructor. Because of this, I cannot directly convert my results to an ObservableCollection. Here is my code: ObservableCollection<MyTasks> visibleTasks = e.Result; var filteredResults = from visibleTask in visibleTasks select visibleTask; filteredResults = filteredResults.Where(p => p.DueDate == DateTime.Today); visibleTasks = filteredResults.ToList(); // This throws a compile time error How can I go from an implicitly typed variable to an observable collection? Thank you

    Read the article

  • How to create an ObservableCollection using LINQ in Silverlight

    - by sonofpirate
    In a non-Silverlight world, it is easy to use LINQ to create an ObservableCollection. This is because the ObservableCollection class has constructors that accept any IEnumerable<T or List<T. However, the Silverlight version does not! This means that code such as: var list = (from item in e.Result select new ViewModel(item)).ToList(); Items = new System.Collections.ObjectModel.ObservableCollection<ViewModel>(list); will not work in Silverlight. Is there another option to make this work besides resorting to a for-each statement?

    Read the article

  • Subscribing to a ObservableCollection via reflection

    - by Julian Lettner
    How can I subscribe to a ObservableCollection<??> without knowing the element type of the collection? Is there a way to do this without too many 'magic strings'? This is a question for the .NET version 3.5. I think 4.0 would make my life much easier, right? Type type = collection.GetType(); if(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(ObservableCollection<>)) { // I cannot cast the collection here ObservableCollection<object> x = collection; } Thanks for your time.

    Read the article

  • Having ObservableCollection Trigger an update

    - by user275561
    So i have something along the lines of private ObservableCollection<ViewModel> _internal; public ObservableCollection<ViewModel> BoundInternal{get;set}; //this is Binded in the Itemssource like ItemSource={Binding BoundInternal} Now In my code i do something like BoundInternal=_internal, However the problem is the BoundInternal isn't trigger any collectionChanged event. I have to use the Add method. So I am wondering if there is a solution to this.

    Read the article

  • How to display two ObservableCollections as a single list in WPF?

    - by nareshbhatia
    I have two ObservableCollections, say ObservableCollection<Cat> and ObservableCollections<Dog>. Cat and Dog both derive from class Pet. I want to display a list of all Pets. How do I do this? I prefer not want create a new ObservableCollection<Pet> by adding items from the two source lists because this list will become stale as more Cats and Dogs are added to the source lists. I can think of two approaches: 1) Create a "Decorator" ObservableCollection that keeps the two source collections as members and iterates over them every time. 2) Create an ObservableCollection<Pet> that does have the combined elements of the two source collections, but is also dependent on the source collections. Thus if a Cat is added to the Cat collection, this collection is notified and it adds the new Cat to itself. Is there a standard way to solve this issue? I don't want to reinvent the wheel!

    Read the article

  • Using LINQ on observable with GroupBy and Sum aggregate

    - by Mark Oates
    I have the following block of code which works fine; var boughtItemsToday = (from DBControl.MoneySpent bought in BoughtItemDB.BoughtItems select bought); BoughtItems = new ObservableCollection<DBControl.MoneySpent>(boughtItemsToday); It returns data from my MoneySpent table which includes ItemCategory, ItemAmount, ItemDateTime. I want to change it to group by ItemCategory and ItemAmount so I can see where I am spending most of my money, so I created a GroupBy query, and ended up with this; var finalQuery = boughtItemsToday.AsQueryable().GroupBy(category => category.ItemCategory); BoughtItems = new ObservableCollection<DBControl.MoneySpent>(finalQuery); Which gives me 2 errors; Error 1 The best overloaded method match for 'System.Collections.ObjectModel.ObservableCollection.ObservableCollection(System.Collections.Generic.List)' has some invalid arguments Error 2 Argument 1: cannot convert from 'System.Linq.IQueryable' to 'System.Collections.Generic.List' And this is where I'm stuck! How can I use the GroupBy and Sum aggregate function to get a list of my categories and the associated spend in 1 LINQ query?! Any help/suggestions gratefully received. Mark

    Read the article

  • issue in ObservableCollection

    - by prince23
    hi, i have an lsit with these data i have a class called information.cs with these properties name,school, parent ex data name school parent kumar fes All manju fes kumar anu frank kumar anitha jss All rohit frank manju anill vijaya manju vani jss kumar soumya jss kumar madhu jss rohit shiva jss rohit vanitha jss anitha anu jss anitha now taking this as an input i wanted the output to be formated with a Hierarchical data when parent is all means it is the topmost level kumar fes All. what i need to do here is i need to create an object[0] and then check in list whether kumar exists as a parent in the list if it exista then add those items as under the object[0] as a parent i need to create one more oject under **manju fes kumar anu frank kumar** if you see this class file its shows how data is formatted. public class SampleProjectData { public static ObservableCollection GetSampleData() { DateTime dtS = DateTime.Now; ObservableCollection<Product> teams = new ObservableCollection<Product>(); teams.Add(new Product() { PDName = "Product1", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3), }); Project emp = new Project() { PName = "Project1", OverallStartTime = dtS + TimeSpan.FromDays(1), OverallEndTime = dtS + TimeSpan.FromDays(6) }; emp.Tasks.Add(new Task() { StartTime = dtS, EndTime = dtS + TimeSpan.FromDays(2), TaskName = "John's Task 3" }); emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(3), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "John's Task 2" }); teams[0].Projects.Add(emp); } return teams; }

    Read the article

  • What is a good pattern for binding a collection of objects coming from WCF, in Silverlight?

    - by Krishna
    Hi there, I've got a question about a Silverlight WCF Databinding pattern: There are many examples about how to bind data using {Binding} expressions in XAML, how to make async calls to a WCF service, set the DataContext property of a element in the UI, how to use ObservableCollections and INotifyPropertyChanged, INotifyCollectionChanged and so on. Background: I'm using the MVVM pattern, and have a Silverlight ItemsControl, whose ItemsSource is set to an ObservableCollection property on my ViewModel object. My view is of course the XAML which has the {Binding}. Say the model object is called 'Metric'. My ViewModel periodically makes calls to a WCF service that returns ObservableCollection. MetricInfo is the data transfer object (DTO). My question is two-fold: Is there any way to avoid copying each property of MetricInfo to the model class - Metric? When the WCF calls completes, is there any way to make sure I sync the items which are in both my local ObservableCollection and the result of the WCF call - without having to first clear out all the items in the local collection and then add all the ones from the WCF call result? thanks, Krishna

    Read the article

  • WPF: Xaml, create an observable collection<object> in xaml in Dot Net 4.0

    - by Aran Mulholland
    the web site says you can in dot net 4.0 I cant seem to do it though, what assesmbly references and xmlns' do i need the following does not work xmlns:coll="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" <coll:ObservableCollection x:TypeArguments="x:Object"> <MenuItem Command="ApplicationCommands.Cut"/> <MenuItem Command="ApplicationCommands.Copy"/> <MenuItem Command="ApplicationCommands.Paste"/> </coll:ObservableCollection>

    Read the article

  • WPF: Xaml, create an observable collection<object> in xaml in .NET 4.0

    - by Aran Mulholland
    the web site says you can in .NET 4.0 I cant seem to do it though, what assesmbly references and xmlns' do i need the following does not work xmlns:coll="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib" <coll:ObservableCollection x:TypeArguments="x:Object"> <MenuItem Command="ApplicationCommands.Cut"/> <MenuItem Command="ApplicationCommands.Copy"/> <MenuItem Command="ApplicationCommands.Paste"/> </coll:ObservableCollection>

    Read the article

  • Missing elements of collection

    - by Neir0
    I have a collection ObservableCollection<string> outoverList And i have a function which call collection outoverList.Add("out:"+element.tagName); Function call collection a few times, but sometimes collection lost elements. We call a function - function adds element - collection has 9 elements(for example) - in the next function calling collection has only 8 elements. One elements be missing. Here Resharpers Find usages log: Search target FindElementHandler.outoverList:ObservableCollection<string> Found 3 usages in solution <FindElementExperiments> (3 items) FindElementHandler.cs (3 items) (50,13) outoverList = new ObservableCollection<string>(); (94,13) outoverList.Add("out:"+element.tagName); (118,13) outoverList.Add("over:" + element.tagName); As you can see i just add elements to collection everywhere. i havent remove elements code. Maybe i did something wrong you can look at screen capture: http://www.youtube.com/watch?v=Ei6dQnHCMIc I am newbie and often encounter with various problems but this bug looks mystic for me. P/S/ Sorry for english

    Read the article

  • Implementing inotifycollectionchanged interface

    - by George
    Hello, I need to implement a collection with special capabilities. In addition, I want to bind this collection to a ListView, Therefore I ended up with the next code (I omitted some methods to make it shorter here in the forum): public class myCollection<T> : INotifyCollectionChanged { private Collection<T> collection = new Collection<T>(); public event NotifyCollectionChangedEventHandler CollectionChanged; public void Add(T item) { collection.Insert(collection.Count, item); OnCollectionChange(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); } protected virtual void OnCollectionChange(NotifyCollectionChangedEventArgs e) { if (CollectionChanged != null) CollectionChanged(this, e); } } I wanted to test it with a simple data class: public class Person { public string GivenName { get; set; } public string SurName { get; set; } } So I created an instance of myCollection class as follows: myCollection<Person> _PersonCollection = new myCollection<Person>(); public myCollection<Person> PersonCollection { get { return _PersonCollection; } } The problem is that the ListView does not update when the collection updates although I implemented the INotifyCollectionChanged interface. I know that my binding is fine (in XAML) because when I use the ObservableCollecion class instead of myCollecion class like this: ObservableCollection<Person> _PersonCollection = new ObservableCollection<Person>(); public ObservableCollection<Person> PersonCollection { get { return _PersonCollection; } } the ListView updates What is the problem?

    Read the article

  • WPF ObservableCollection CollectionView.CurrentChanged not firing.

    - by EL
    Hi folks, I have a problem with one of my ICollectionViews. The ICollectionView's CurrentChanged event i not firing. Please see my code below. XAML: <!-- Publication --> <TextBlock Name="tbkPublication" Text="{x:Static abConst:Print.tbkPublicationText}" Grid.Row="0" Grid.Column="0" Margin="3" ></TextBlock> <ComboBox Grid.Column="1" Grid.Row="0" Margin="3" Name="cmbPublication" BorderThickness="1" ItemsSource="{Binding Path=EnterpriseList}" DisplayMemberPath="Name" SelectedValuePath="Value" SelectedIndex="0" IsSynchronizedWithCurrentItem="True" /> <!-- Distribution Area Region --> <TextBlock Name="tbkDistributionArea" Text="{x:Static abConst:Print.tbkDistributionAreaText}" Grid.Row="1" Grid.Column="0" Margin="3" ></TextBlock> <ComboBox Grid.Column="1" Grid.Row="1" Margin="3" Name="cmbDistributionArea" BorderThickness="1" ItemsSource="{Binding Path=ZonesList}" DisplayMemberPath="Name" SelectedValuePath="Value" SelectedIndex="0" IsSynchronizedWithCurrentItem="True" /> AND C# (ViewModel) #region Properties public ObservableCollection<GenericNameValuePair<int, string>> EnterpriseList { get { return _abEnterpriseList; } set { _abEnterpriseList = value; } } public ObservableCollection<GenericNameValuePair<int, string>> ZonesList { get { return _abZonesList; } set { _abZonesList = value; } } #endregion private void InitCollections() { _collectionViewEnterprise = CollectionViewSource.GetDefaultView(EnterpriseList); _collectionViewZone = CollectionViewSource.GetDefaultView(ZonesList); //Replace if(_collectionViewEnterprise == null) throw new NullReferenceException("Enterprise collectionView is null."); if (_collectionViewZone == null) throw new NullReferenceException("Zone collectionView is null."); _collectionViewEnterprise.CurrentChanged += new EventHandler(OnCollectionViewEnterpriseCurrentChanged); _collectionViewZone.CurrentChanged += new EventHandler(OnCollectionViewZoneCurrentChanged); } Please help. Thanks in advance.

    Read the article

  • Problem Binding a ObservableCollection to a ListBox in WPF/MVVM

    - by alexqs
    I'm working in some code , using wpf and starting to use mvvm. So far i have no problem, when i have one element and I have to show the values of it in the screen (binding of the specific name of the property). But now, i have to work with a property list , not knowing the names of it. So I created a class, named GClass, that only have two propierties, name and value. I created the ObservableCollection, and fill for now with direct values, and asign the view (lstview) datacontext with the object i have created. But I cant see any result, it always shows a blank listbox. Can someone tell me if see why is happening ? Code of c# VDt = new ObservableCollection<GClass>(); var vhDt = message.SelectSingleElement(typeof (Vh)) as Vehiculo; if(vhDt != null) { VDt.Add(new GClass() {Name = "Numero: ", Value = ""}); VDt.Add(new GClass() {Name = "Marca: ", Value = ""}); VDt.Add(new GClass() {Name = "Conductor: ", Value = ""}); lstview.DataContext = this; _regionManager.RegisterViewWithRegionInIndex(RegionNames.MainRegion, lstview, 0); Code of the view <ListBox Margin="5,5,5,25" ItemsSource="{Binding VDt}"> <ListBox.Template> <ControlTemplate> <ListViewItem Content="{Binding Name}"></ListViewItem> <ListViewItem Content="{Binding Value}"></ListViewItem> </ControlTemplate> </ListBox.Template> </ListBox> I have research here, but i cant see, what I'm doing wrong. I will apreciate if someone help me.

    Read the article

  • WPF Empty Row in ItemsControl Binding with ObservableCollection

    - by YoMo
    I have ItemsControl Binding with ObservableCollection, every think is oky excipt when ObservableCollection was empty the ItemsControl showing one empty row !! <ItemsControl Visibility="Visible" ItemsSource="{Binding ocItemsinInvoice,Mode=TwoWay}" x:Name="test" Margin="10,-32,0,207" Width="412" HorizontalAlignment="Left"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="1" VerticalAlignment="Top" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button x:Name="btnOpenInvoice" Style="{StaticResource OpenInvoicesButton}" FontSize="12" Width="300" Height="60" Foreground="#ff252526"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding Item.ItemName}" HorizontalAlignment="Center" VerticalAlignment="Center" /> </StackPanel> </Button> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> How can I remove it?

    Read the article

  • Silverlight 4 DataBinding: Binding to ObservableCollection<string> not working anymore

    - by Kurt
    Upgrading from SL3 - SL4. First problem: this throws a parser exception: <StackPanel Name={Binding} /> (same with x:Name) Collection is ObservableCollection<string>. Worked fine in SL3. So it seems that SL4 doen't allow binding to the Name property. Huh? So: changed to <StackPanel Tag={Binding} /> ... since I just need to ID the control in code behind. So here's the bug ('cuz this has got to be a bug!): In this frag, AllAvailableItems is an ObservableCollection<string>: <ItemsControl Name="lbItems" ItemsSource="{Binding AllAvailableItems}" Height="Auto" Width="Auto" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="12,6,0,0"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <CheckBox Tag="{Binding}" Checked="ItemChecked_Click" Unchecked="ItemUnchecked_Click" Style="{StaticResource CheckBoxStyle}" Grid.Row="0"> <CheckBox.Content> <TextBlock Text="{Binding}" Style="{StaticResource FormLJustStyle}" /> </CheckBox.Content> </CheckBox> <StackPanel Tag="{Binding}" Orientation="Vertical" Grid.Row="1"> <configControls:ucLanguage /> <!-- simple user control --> </StackPanel> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> In the code behind, I use a recursive function to find the Dependency object with either the Name or Tag property provided: public static T FindVisualChildByName<T>(DependencyObject parent, string name, DependencyProperty propToUse) where T : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) { var child = VisualTreeHelper.GetChild(parent, i); string controlName = child.GetValue(propToUse) as string; if (controlName == name) { return child as T; } else { T result = FindVisualChildByName<T>(child, name, propToUse); if (result != null) return result; } } return null; } OK, get this: in the code behind, I can get the control that is ORDERED FIRST in the XAML! In other words, if I put the CheckBox first, I can retrieve the CheckBox, but no StackPanel. And vice-versa. This all worked fine in SL3. Any help, ideas ... ? Thanks - Kurt

    Read the article

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