.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

How do I bind the ModelItem collection to combobox in XAML

Posted By:      Posted Date: October 08, 2010    Points: 0   Category :Windows Application


I need to create an custom activity with a combo box that need to display all the activity name within the same parent.

Below are the code snippets that failed to list out the activities name. Anyone has any ideas to make this work?

<ComboBox Name="ActivityList" 
  ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type sas:Sequence}},Path=ModelItem.Activities}"


View Complete Post

More Related Resource Links

How to bind to DisplayMemberPath in a customercontrol that derived from ComboBox?

Hello, All: I need a customer control which derives from ComboBox. In its resource file I have the style:   <Style TargetType="{x:Type local:MyComboBox}">             <Setter Property="SnapsToDevicePixels" Value="True"></Setter>             <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>             <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>             <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>         <Setter Property="ItemTemplate">                 <Setter.Value>                     <HierarchicalDataTemplate>                     <CheckBox Content="{Binding Path=DisplayMemberPath,Mode=TwoWay,RelativeSource={RelativeSource

How can I bind 2 comboboxes in 2 different WPF windows to the same observable collection?

I have a pretty simple (or deceptively not so) question. I have a WPF application that has a nicely bound combo to an ObservableCollection. I am trying to correctly implement MVVM. One thing I am trying to do (as a test for other things I need) is to have a combo in a popup window have the same content (2-way data bound) as the combo on the main window. I have the main window set up with no issues. <     ComboBox Height="23" HorizontalAlignment="Left" Margin="110,197,0,0" Name="comboBox1" VerticalAlignment="Top" Width="194" ItemsSource="{Binding MyStuff}"/> where "MyStuff" is an ObservableCollection. My problem comes when I create a new wpf application (separate project), put a combo on it, launch it from a button in the first project, and try to bind the combo to the same ItemsSource. I can't seem to figure out the syntax. My 2 issues are as follows: 1. I think the XMAL in the child window needs to have something like this: <     ComboBox Height="23" HorizontalAlignment="Left" Margin="110,257,0,0" Name="comboBox1" VerticalAlignment="Top" Width="194" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ObservableCollection}, AncestorLevel=2}

XAML Combobox

Following is a 2 columns XAML Listview.  The program has a Timesheet entity related to a second Entity Consultant.  The multiplicity is many to one.  The Timesheet navigation properties is Consultant. In the second column, I can show the consultant name (Consultant.Name).  All other properties are ok. My problem is that I need to replace the textbox with a combobox as in column one (Consultant lookup).  But the combobox always shows the first item in the consultant list.  I hope you can help me. Thank you.       <GridViewColumn Header="Consultant" Width="200"> <GridViewColumn.CellTemplate>       <DataTemplate>       <ComboBox Name="cboConsultant" Margin="-6,0,-6,0"     IsEditable="False"     ItemsSource="{Binding Source={StaticResource ConsultantLookup}}"     DisplayMemberPath="Name"     SelectedValue="{Binding Path=ConsultantID}"     SelectedValuePath="ConsultantID" />       </DataTemplate>       </GridViewColumn.CellTemplate>       </GridViewColumn>       <GridViewColumn Header="C

How to Bind ListBox to ComboBox's SelectedItem

I have a ComboBox bound to a list of custom objects (Person). Each Person has a Friends collection. I want a ListBox below the ComboBox to contain a list of Friends depending on the Person selected in the ComboBox above it.   Something like: <ComboBox x:Name="MyComboBox" ItemsSource="{Binding People}"/> <ListBox ItemsSource="{Binding Element=MyComboBox, Path=SelectedItem.Friends}"/>   It doesn't work (null reference, I'm assuming because the SelectedItem.Friends is the wrong syntax.   Any pointers?

WPF Combobox Bind FallbackValue to Property

What I am wanting to do seems fairly simple, but WPF doesn't seem to like it. Basically I am binding a ComboBox's SelectedValue to my object:       <ComboBox SelectedValue="{Binding SendToBinLocation}" Name="cboToBin" Width="100" DisplayMemberPath="BinLocation" SelectedValuePath="BinLocation" ItemsSource="{Binding ToBinList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" BorderBrush="{Binding Path=SendToBinLocation, Converter={StaticResource MissingBinConverter}, Mode=OneWay}"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock FontSize="16" Text="{Binding BinLocation}"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox>  This works fine. However, I am wanting to specify a default value for the combobox in the event ToBinLocation is empty or null. I can achieve this by hard-coding in FallBackValue=somevalue, but this is not what I want to do. What I would like to do is bind the FallBackValue to another property of the object. You can't databind to fallBackValue because it is a dependency property, so how would I go about specifying the FallBackValue with another property on the object? The idea here is that if the SendToBinLocation is null or empty, the Comboxvalu

Bind An Already Bound TextBox to ComboBox SelectedItem


Hey all,


If I have a TextBox that is already two-way bound to something, but I also want it so when a ComboBox SelectedItem changes, then the TextBox's Text property is set to the new SelectedItem.


Here's what I have so far, I added the comment where the TextBox is, which I would like to also be bound to the ComboBox below this.


        <ListView Grid.Row="2" 
             DataContext="{Binding ScriptParameters}"

Bind custom list to combobox


Hi, I have a custom list which I newed to binf to a combo box, my class is as followes

Class ComboData
    Public id As String
    Public V1 As String
    Public V2 As String
End Class

I am trying the following but nothing is dispalyed in the combobox, no errors....

        Dim Listdata As New List(Of ComboData)()
        Listdata.Add(New ComboData() With {.id = "1", .V1 = "test", .V2 = "test2"})
        Listdata.Add(New ComboData() With {.id = "2", .V1 = "test2", .V2 = "test3"})
        cboSmtpServer.ItemsSource = Listdata
        cboSmtpServer.DisplayMemberPath = "V1"
        cboSmtpServer.SelectedValuePath = "id"
        cboSmtpServer.SelectedIndex = 0
        cboSmtpServer.SelectedValue = "V1"

What is missing


Thanks in advance

How to set a wpf combobox displaymemberitem to a column in 1 table and bind text displayed to a colu


I have a combobox that has a datacontext set to a 'Customer Type' that is a customer CRUD window in WPF that itself has a datacontext of 'Customer' - when i scroll through my customer table entries that have been populated into a listbox, all of the corresponding textboxes on my CRUD window update to reflect the values stored in the Customer table except the combobox.  If I change the datacontext of the combobox to be 'Customer' the text updates correctly when scrolling through but the dropdown contents are now duplicated to match the number of records.  So my problem is this;

How can I display the itemssource as the 'Customer Type.Customer_Type' datacontext, but display the Text as 'Customer.Customer_Type'?

The closest i could compare it to would be a winforms example of setting the combo's DataSource to 'Customer_Type' on the combo with a displaymember of 'Customer_Type' and then making the DataBindings 'Text' property of the combo to be 'Customer.Customer_Type' so it displays the value stored in customer but as soon as you drop it down it shows non-repeated values that are contained in customer_type.customer_type.

Right now in wpf if the datacontext is customer, the combo displays customer_type as follows:






Bind ComboBox in DataGrid row



I want to bind ComboBox to database table (via ADO.NET Entity Framework) and put it in DataGrid. Now I have DataGrid with binded TextBlock, but when I try to bind ComboBox it doesn't work.


I have table with list if countries and table users, where each user has foreign key of country where he lives.

I want to show in DataGrid user details like:

Alex Gorr     Canada     al.gorr@email.yo


And when I click on country field I want to see ComboBox with list of countries from table countries.

How can I do it?


Binding a Collection to a ComboBox


The following is a the class, a list of which I wish to display in a WPF combo box
    public class DivisionItem

        private int _divn_ID = -1;
        private string _divn_Nm = "";
        private int _divn_Mgr = -1;

        private string _addrLn1 =&nb

using ImageSource collection in xaml (getting error Only public classes can be used in markup. 'Bit


Hy everybody, I made a custom control that has a property of type ObservableCollection<ImageSource>.


My problem is that if i use the control as is and set the list of frames from xaml everything works fine, but if I use my control as part of a template (for example a Button template) i get the error


" Only public classes can be used in markup. 'BitmapFrameDecode' type is not public.  "

I have no idea how to fix this..can anyone help me? Thank you very much!

Catalin Toma

using ImageSource collection in xaml (getting error Only public classes can be used in markup. 'Bit


Hy everybody, I made a custom control that has a property of type ObservableCollection<ImageSource>.


My problem is that if i use the control as is and set the list of frames from xaml everything works fine, but if I use my control as part of a template (for example a Button template) i get the error


This is my simplified control:



public partial class MultiFrameImage : UserControl
    public MultiFrameImage()
      ImageSources = new ObservableCollection<ImageSource>();


    public ObservableCollection<ImageSource> ImageSources
        return base.GetValue(ImageSourcesProperty) as ObservableCollection<ImageSource>;
    public DependencyProperty ImageSourcesProperty = DependencyProperty.Register("ImageSources",typeof(ObservableCollection<ImageSource>),typeof(MultiFrameImage));


Now,if I initialize the control like this everything works fine:



How to bind wpfdatagrid with collection of collection in MVVM pattern?


Hi everyone,

I am using MVVM pattern. I have some dynamic data and i want to bind it with datagrid. I converted my data in a collection which also contain anaother collection in following way.

First i create a class in my Model,which has some properties like this

namespace DummyDataGridBindingApplication.Models
   public class EntityAttribute
        public string AttributeName
        public string AttributeValue
        public string AttributDataType 

Is it possible to bind a xaml control's image source directly from the resource file ?


Hi all


Is it possible to bind a xaml control's image source directly from the resource file ?




syntax to specify subobject collection as xaml resource


Sorry for the vague subject title.

A UserControl has an ObservableCollection

the UserControl is instantiated in MainWindow.xaml

I want to specify the collection defined within the usercontrol as a resource in MainWindow.xaml

I thought the syntax might be like the following


<local:myUserControl.MyCollection x:key="whatever"/>


However this produces an error "The attachable property 'MyCollection' was not found in type 'myUserControl'




What's new in XAML of .NET 4.0

With .NET 4.0 Microsoft will bring up a improved version of XAML. This arcitle shows you the language enhancements they made.
Easy Object References with {x:Reference}

Built-in Types

Generics in XAML with x:TypeArguments

Support for Arbitrary Dictionary Keys

Use of Non-Default Constructors with x:Arguments

Use of Static Factory Methods with x:FactoryMethod

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.
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