Search Results

Search found 71 results on 3 pages for 'gridviewcolumn'.

Page 2/3 | < Previous Page | 1 2 3  | Next Page >

  • How do I change text color on the selected row inside a ListView/GridView? (using Expression Dark th

    - by Thiado de Arruda
    I'm using theExpression Dark WPF Theme(http://wpfthemes.codeplex.com/) with a ListView(view property set to a GridView) to display some user data like the following : <ListView Grid.Row="1" ItemsSource="{Binding RegisteredUsers}" SelectedItem="{Binding SelectedUser}" > <ListView.View> <GridView> <GridViewColumn Header="Login" DisplayMemberBinding="{Binding Login}" Width="60"/> <GridViewColumn Header="Full Name" DisplayMemberBinding="{Binding FullName}" Width="180"/> <GridViewColumn Header="Last logon" DisplayMemberBinding="{Binding LastLogon}" Width="120"/> <GridViewColumn Header="Photo" Width="50"> <GridViewColumn.CellTemplate> <DataTemplate> <Image Source="{Binding Photo}" Width="30" Height="35"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> The rows have white text with a dark background and white background when selected, however the text color doesnt change when selected and it makes very difficult to read, I would like the text to have a dark color when the row is selected. I have searched for a way to style the text color but with no success, here is the control template for the ListViewItem : <Border SnapsToDevicePixels="true" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2" x:Name="border"> <Grid Margin="2,0,2,0"> <Rectangle x:Name="Background" IsHitTestVisible="False" Opacity="0.25" Fill="{StaticResource NormalBrush}" RadiusX="1" RadiusY="1"/> <Rectangle x:Name="HoverRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource NormalBrush}" RadiusX="1" RadiusY="1"/> <Rectangle x:Name="SelectedRectangle" IsHitTestVisible="False" Opacity="0" Fill="{StaticResource SelectedBackgroundBrush}" RadiusX="1" RadiusY="1"/> <GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="0,2,0,2" VerticalAlignment="Stretch" /> </Grid> </Border> The trigger that changes the background color simply applies an animation to change the 'SelectedRectangle' opacity, but I cant change the text color on the same trigger(I tried using a setter for the foreground color on the ListViewItem, but with no success). Does someone have a clue on that?

    Read the article

  • WPF ListView as a DataGrid – Part 2

    - by psheriff
    In my last blog post I showed you how to create GridViewColumn objects on the fly from the meta-data in a DataTable. By doing this you can create columns for a ListView at runtime instead of having to pre-define each ListView for each different DataTable. Well, many of us use collections of our classes and it would be nice to be able to do the same thing for our collection classes as well. This blog post will show you one approach for using collection classes as the source of the data for your ListView.  Figure 1: A List of Data using a ListView Load Property NamesYou could use reflection to gather the property names in your class, however there are two things wrong with this approach. First, reflection is too slow, and second you may not want to display all your properties from your class in the ListView. Instead of reflection you could just create your own custom collection class of PropertyHeader objects. Each PropertyHeader object will contain a property name and a header text value at a minimum. You could add a width property if you wanted as well. All you need to do is to create a collection of property header objects where each object represents one column in your ListView. Below is a simple example: PropertyHeaders coll = new PropertyHeaders(); coll.Add(new PropertyHeader("ProductId", "Product ID"));coll.Add(new PropertyHeader("ProductName", "Product Name"));coll.Add(new PropertyHeader("Price", "Price")); Once you have this collection created, you could pass this collection to a method that would create the GridViewColumn objects based on the information in this collection. Below is the full code for the PropertyHeader class. Besides the PropertyName and Header properties, there is a constructor that will allow you to set both properties when the object is created. C#public class PropertyHeader{  public PropertyHeader()  {  }   public PropertyHeader(string propertyName, string headerText)  {    PropertyName = propertyName;    HeaderText = headerText;  }   public string PropertyName { get; set; }  public string HeaderText { get; set; }} VB.NETPublic Class PropertyHeader  Public Sub New()  End Sub   Public Sub New(ByVal propName As String, ByVal header As String)    PropertyName = propName    HeaderText = header  End Sub   Private mPropertyName As String  Private mHeaderText As String   Public Property PropertyName() As String    Get      Return mPropertyName    End Get    Set(ByVal value As String)      mPropertyName = value    End Set  End Property   Public Property HeaderText() As String    Get      Return mHeaderText    End Get    Set(ByVal value As String)      mHeaderText = value    End Set  End PropertyEnd Class You can use a Generic List class to create a collection of PropertyHeader objects as shown in the following code. C#public class PropertyHeaders : List<PropertyHeader>{} VB.NETPublic Class PropertyHeaders  Inherits List(Of PropertyHeader)End Class Create Property Header Objects You need to create a method somewhere that will create and return a collection of PropertyHeader objects that will represent the columns you wish to add to your ListView prior to binding your collection class to that ListView. Below is a sample method called GetProperties that builds a list of PropertyHeader objects with properties and headers for a Product object. C#public PropertyHeaders GetProperties(){  PropertyHeaders coll = new PropertyHeaders();   coll.Add(new PropertyHeader("ProductId", "Product ID"));  coll.Add(new PropertyHeader("ProductName", "Product Name"));  coll.Add(new PropertyHeader("Price", "Price"));   return coll;} VB.NETPublic Function GetProperties() As PropertyHeaders  Dim coll As New PropertyHeaders()   coll.Add(New PropertyHeader("ProductId", "Product ID"))  coll.Add(New PropertyHeader("ProductName", "Product Name"))  coll.Add(New PropertyHeader("Price", "Price"))   Return collEnd Function WPFListViewCommon Class Now that you have a collection of PropertyHeader objects you need a method that will create a GridView and a collection of GridViewColumn objects based on this PropertyHeader collection. Below is a static/Shared method that you might put into a class called WPFListViewCommon. C#public static GridView CreateGridViewColumns(  PropertyHeaders properties){  GridView gv;  GridViewColumn gvc;   // Create the GridView  gv = new GridView();  gv.AllowsColumnReorder = true;   // Create the GridView Columns  foreach (PropertyHeader item in properties)  {    gvc = new GridViewColumn();    gvc.DisplayMemberBinding = new Binding(item.PropertyName);    gvc.Header = item.HeaderText;    gvc.Width = Double.NaN;    gv.Columns.Add(gvc);  }   return gv;} VB.NETPublic Shared Function CreateGridViewColumns( _    ByVal properties As PropertyHeaders) As GridView  Dim gv As GridView  Dim gvc As GridViewColumn   ' Create the GridView  gv = New GridView()  gv.AllowsColumnReorder = True   ' Create the GridView Columns  For Each item As PropertyHeader In properties    gvc = New GridViewColumn()    gvc.DisplayMemberBinding = New Binding(item.PropertyName)    gvc.Header = item.HeaderText    gvc.Width = [Double].NaN    gv.Columns.Add(gvc)  Next   Return gvEnd Function Build the Product Screen To build the window shown in Figure 1, you might write code like the following: C#private void CollectionSample(){  Product prod = new Product();   // Setup the GridView Columns  lstData.View = WPFListViewCommon.CreateGridViewColumns(       prod.GetProperties());  lstData.DataContext = prod.GetProducts();} VB.NETPrivate Sub CollectionSample()  Dim prod As New Product()   ' Setup the GridView Columns  lstData.View = WPFListViewCommon.CreateGridViewColumns( _       prod.GetProperties())  lstData.DataContext = prod.GetProducts()End Sub The Product class contains a method called GetProperties that returns a PropertyHeaders collection. You pass this collection to the WPFListViewCommon’s CreateGridViewColumns method and it will create a GridView for the ListView. When you then feed the DataContext property of the ListView the Product collection the appropriate columns have already been created and data bound. Summary In this blog you learned how to create a ListView that acts like a DataGrid using a collection class. While it does take a little code to do this, it is an alternative to creating each GridViewColumn in XAML. This gives you a lot of flexibility. You could even read in the property names and header text from an XML file for a truly configurable ListView. NOTE: You can download the complete sample code (in both VB and C#) at my website. http://www.pdsa.com/downloads. Choose Tips & Tricks, then "WPF ListView as a DataGrid – Part 2" from the drop-down. Good Luck with your Coding,Paul Sheriff ** SPECIAL OFFER FOR MY BLOG READERS **Visit http://www.pdsa.com/Event/Blog for a free eBook on "Fundamentals of N-Tier".  

    Read the article

  • WPF ListView as a DataGrid – Part 3

    - by psheriff
    I have had a lot of great feedback on the blog post about turning the ListView into a DataGrid by creating GridViewColumn objects on the fly. So, in the last 2 parts, I showed a couple of different methods for accomplishing this. Let’s now look at one more and that is use Reflection to extract the properties from a Product, Customer, or Employee object to create the columns. Yes, Reflection is a slower approach, but you could create the columns one time then cache the View object for re-use. Another potential drawback is you may have columns in your object that you do not wish to display on your ListView. But, just because so many people asked, here is how to accomplish this using Reflection.   Figure 1: Use Reflection to create GridViewColumns. Using Reflection to gather property names is actually quite simple. First you need to pass any type (Product, Customer, Employee, etc.) to a method like I did in my last two blog posts on this subject. Below is the method that I created in the WPFListViewCommon class that now uses reflection. C#public static GridView CreateGridViewColumns(Type anyType){  // Create the GridView  GridView gv = new GridView();  GridViewColumn gvc;   // Get the public properties.  PropertyInfo[] propInfo =          anyType.GetProperties(BindingFlags.Public |                                BindingFlags.Instance);   foreach (PropertyInfo item in propInfo)  {    gvc = new GridViewColumn();    gvc.DisplayMemberBinding = new Binding(item.Name);    gvc.Header = item.Name;    gvc.Width = Double.NaN;    gv.Columns.Add(gvc);  }   return gv;} VB.NETPublic Shared Function CreateGridViewColumns( _  ByVal anyType As Type) As GridView  ' Create the GridView   Dim gv As New GridView()  Dim gvc As GridViewColumn   ' Get the public properties.   Dim propInfo As PropertyInfo() = _    anyType.GetProperties(BindingFlags.Public Or _                          BindingFlags.Instance)   For Each item As PropertyInfo In propInfo    gvc = New GridViewColumn()    gvc.DisplayMemberBinding = New Binding(item.Name)    gvc.Header = item.Name    gvc.Width = [Double].NaN    gv.Columns.Add(gvc)  Next   Return gvEnd Function The key to using Relection is using the GetProperties method on the type you pass in. When you pass in a Product object as Type, you can now use the GetProperties method and specify, via flags, which properties you wish to return. In the code that I wrote, I am just retrieving the Public properties and only those that are Instance properties. I do not want any static/Shared properties or private properties. GetProperties returns an array of PropertyInfo objects. You can loop through this array and build your GridViewColumn objects by reading the Name property from the PropertyInfo object. Build the Product Screen To populate the ListView shown in Figure 1, you might write code like the following: C#private void CollectionSample(){  Product prod = new Product();   // Setup the GridView Columns  lstData.View =      WPFListViewCommon.CreateGridViewColumns(typeOf(Product));  lstData.DataContext = prod.GetProducts();} VB.NETPrivate Sub CollectionSample()  Dim prod As New Product()   ' Setup the GridView Columns  lstData.View = WPFListViewCommon.CreateGridViewColumns( _       GetType(Product))  lstData.DataContext = prod.GetProducts()End Sub All you need to do now is to pass in a Type object from your Product class that you can get by using the typeOf() function in C# or the GetType() function in VB. That’s all there is to it! Summary There are so many different ways to approach the same problem in programming. That is what makes programming so much fun! In this blog post I showed you how to create ListView columns on the fly using Reflection. This gives you a lot of flexibility without having to write extra code as was done previously. NOTE: You can download the complete sample code (in both VB and C#) at my website. http://www.pdsa.com/downloads. Choose Tips & Tricks, then "WPF ListView as a DataGrid – Part 3" from the drop-down. Good Luck with your Coding,Paul Sheriff ** SPECIAL OFFER FOR MY BLOG READERS **Visit http://www.pdsa.com/Event/Blog for a free eBook on "Fundamentals of N-Tier".  

    Read the article

  • WPF: Checkbox in a ListView/Gridview--How to Get ListItem in Checked/Unchecked Event?

    - by Phil Sandler
    In the code behind's CheckBox_Checked and CheckBox_Unchecked events, I'd like to be able to access the item in MyList that the checkbox is bound to. Is there an easy way to do this? <ListView ItemsSource="{Binding Path=MyList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" MinHeight="100" MaxHeight="100"> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <CheckBox Margin="-4,0,-4,0" IsChecked="{Binding MyBoolProperty}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView>

    Read the article

  • WPF Combobox in Gridview's column

    - by plotnick
    I got a combobox in the grid's column: <ListView> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> Now, in the SelectionChanged() of ComboBox I'm trying to change some value in an other column but the same row. And I can't find how to get the current row. none of the following doesn't work ListView.Items.CurrentPosition ListView.Items.CurrentItem please guys help me

    Read the article

  • ListView GridView column

    - by plotnick
    I got a ListView with GridView and GridViewColumns in it. <ListView> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> Now I want in my code to disable the Combobox or entire column. And I don't know how to do it. Help me please.

    Read the article

  • WPF Notify changes on object

    - by Erik Z
    I have a gridview were I define some columns, like this... <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding MyProp}" /> </DataTemplate> </GridViewColumn.CellTemplate> I bind my gridview to a collection and implemts INotifyPropertyChanged in the property MyProp. This works well and any changes of MyProp are reflected to the gridview. If I add another column that is bound to the object itself I dont get any notifications/updates. My code... <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Converter={StaticResource myConverter}}"/> </DataTemplate> </GridViewColumn.CellTemplate> I think I need something like INotifyPropertyChanged for the object but I have no idea how to do this. Any suggestions?

    Read the article

  • Can I change the binding source to another source in XAML?

    - by No hay Problema
    Hi guys, I want to do a very simple thing, can you point me on the right direction? I want to change the source in XAML to another object source, let me put you an example: I have a Listview, bound to a "Model A", it has many properties, but one is called "Total". This property is not shown on the View Each ListviewItem has its own source (ItemsSource), BUT, one of the fields should show "Total" from "Model A" Caveat: I am implementing MVVM, so the "Model A" is assigned as a VM DataSource, XAML knows nothing about it. So, in my perfect world the XAML should look like this: <GridViewColumn Header="Total" Width="150"> <GridViewColumn.CellTemplate> <DataTemplate> <Label Content="{Binding Source=<The source of LISTVIEW> Path=Total}"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> I have tried RelativeSource but that points me to the XAML object, I want the source of it, is it possible? Thanks

    Read the article

  • WPF ListView Button - Associate multiple images

    - by Narayanan
    I have a listview in a WPF application that has a button in one of its columns. I associate a image to the button control. I want to configure different images for this button based on the How do I write the XAML in this scenario??? This is what I have already: <ControlTemplate x:Key="IconButtonAddProfile" TargetType="{x:Type Button}"> <Grid> <Image x:Name="myimage" Source="rofile.png" Height="27" Width="65" /> <Border> <ContentPresenter Content="{TemplateBinding Content}"/> </Border> </Grid> </ControlTemplate> <ListView.View> <GridView> <GridViewColumn Header="Security" Width="50"> <GridViewColumn.CellTemplate> <DataTemplate> <Button Template="{StaticResource IconButtonLockSecure}" DataContext="{Binding}" MinHeight="20" MinWidth="50" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </ListView.View>

    Read the article

  • Why the databinding fails in ListView (WPF) ?

    - by Ashish Ashu
    I have a ListView of which ItemSource is set to my Custom Collection. I have defined a GridView CellTemplate that contains a combo box as below : <ListView MaxWidth="850" Grid.Row="1" SelectedItem="{Binding Path = SelectedCondition}" ItemsSource="{Binding Path = Conditions}" FontWeight="Normal" FontSize="11" Name="listview"> <ListView.View> <GridView> <GridViewColumn Width="175" Header="Type"> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox Style="{x:Null}" x:Name="TypeCmbox" Height="Auto" Width="150" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding Path = MyType}" ItemsSource="{Binding Path = MyTypes}" HorizontalAlignment="Center" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </ListView> My Custom collection is the ObservableCollection. I have a two buttons - Move Up and Move Down on top of the listview control . When user clicks on the Move Up or Move Down button I call MoveUp and MoveDown methods of Observable Collection. But when I Move Up and Move Down the rows then the Selected Index of a combo box is -1. I have ensured that selectedItem is not equal to null when performing Move Up and Move Down commands. Please Help!!

    Read the article

  • WPF ListView column auto sizing

    - by Diego Mijelshon
    Let's say I have the following ListView: <ListView ScrollViewer.VerticalScrollBarVisibility="Auto"> <ListView.View> <GridView> <GridViewColumn Header="Something" DisplayMemberBinding="{Binding Path=ShortText}" /> <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Path=VeryLongTextWithCRs}" /> <GridViewColumn Header="Something Else" DisplayMemberBinding="{Binding Path=AnotherShortText}" /> </GridView> </ListView.View> </ListView> I'd like the short text columns to always fit in the screen, and the long text column to use the remaining space, word-wrapping if necessary. Is that possible?

    Read the article

  • Appearance of a WPF ListView under Windows Vista and Windows XP is not the same

    - by rem
    In a WPF application I have a ListView: <ListView Name="ItemSelList" ItemsSource="{Binding ItemColl}" SelectionChanged="ItemSelList_SelectionChanged"> <ListView.View> <GridView> <GridViewColumn Header="Date" Width="90" DisplayMemberBinding="{Binding Date}"/> <GridViewColumn Header="Time" Width="90" DisplayMemberBinding="{Binding Time}"/> <GridViewColumn Header="Description" Width="250" DisplayMemberBinding="{Binding Description}"/> </GridView> </ListView.View> </ListView> When running application under Windows Vista, everything is OK. When running under Windows XP - the default font size of ListView's rows is too small and rows of the ListView don't change color when user hovers with a mouse over them. How to do so that ListView appearance under Windows XP is the same as under Vista?

    Read the article

  • Wrap or adorn wpf listview datatemplate

    - by Chris Cap
    I'm attempting to essentially wrap the contents of a DateTemplate in a listview gridview column with a border. What I want to know is if it's possible to supply an adorner that will surround that template so that I don't have to specify the border in every single datatemplate on every column (which is what I'm doing now). I've got something like this, but I know it's not right <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="TemplateContent"> <Setter.Value> <ControlTemplate> <StackPanel> <Border BorderBrush="Green" BorderThickness="1"> <AdornedElementPlaceholder /> </Border> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> This complains that Templatecontent is not a valid type. I've also tried with DataTemplate and that doesn't work either (understandably so). I know I could just create a DataTemplate, however the content for each column is different. At the very least, it binds to different fields. I'm wondering if there's a solution using a dynamic resource, but I don't know much about it. Thanks for your help EDIT: here's a sample of my listview <ListView ItemsSource="{Binding Path=OrderLines}" ItemContainerStyle="{StaticResource ResourceKey=ListViewItemContainerStyle}"> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox MaxWidth="30" Width="30" MaxLength="2" Text="{Binding Path=Quantity,ValidatesOnDataErrors=True}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridView> <ListView.View> </ListView> Essentially I want to wrap that text box in the data template and any other items in additional columns.

    Read the article

  • Datatemplates while using theme does not work - WPF

    - by bobjink
    I am using the theme DarkExpression from WPF Futures. It does not seem to work well with datatemplates. Scenario 1: Here is how it looks like without datatemplates: Pic 1 Code: <ListView Name="playlistListView" ItemsSource="{Binding PlaylistList}" Margin="0" SelectionChanged="DatabindedPlaylistListView_SelectionChanged" Background="{x:Null}" Opacity="0.98"> <ListView.View> <GridView> <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Name}"> <GridViewColumnHeader HorizontalContentAlignment="Left" Content="Playlist" Tag="Playlist"/> </GridViewColumn> </GridView> </ListView.View> </ListView> Scenario 2: Here is how it looks like trying to use datatemplates while using the theme: Pic 2 Code: <ListView Name="playlistListView" ItemsSource="{Binding PlaylistList}" Margin="0" SelectionChanged="DatabindedPlaylistListView_SelectionChanged" Background="{x:Null}" Opacity="0.98"> <ListView.ItemTemplate> <DataTemplate> <Grid> <UserControls:SongDataTemplate Margin="4" /> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> Scenario 3: Here is how it looks like trying to use datatemplates while overriding the theme: Pic3 Code: <UserControl.Resources> <Style x:Key="ListViewItemStretch" TargetType="{x:Type ListViewItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="Background" Value="Transparent" /> </Style> </UserControl.Resources> <Grid x:Name="LayoutRoot"> <ListView Name="playlistListView" ItemContainerStyle="{StaticResource ListViewItemStretch}" ItemsSource="{Binding PlaylistList}" Margin="0" SelectionChanged="DatabindedPlaylistListView_SelectionChanged" Background="{x:Null}" Opacity="0.98"> <ListView.ItemTemplate> <DataTemplate> <Grid> <UserControls:SongDataTemplate Margin="4" /> </Grid> </DataTemplate> </ListView.ItemTemplate> </ListView> I want to keep the theme style but I also want to use datatemplates to define how a playlist should look like. Any suggestions? Note: In scenario 2 and 3 I had to remove <ListView.View> <GridView> <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Name}"> <GridViewColumnHeader HorizontalContentAlignment="Left" Content="Playlist" Tag="Playlist"/> </GridViewColumn> </GridView> </ListView.View> Before the datatemplate would be used.

    Read the article

  • Get data from selected row in Gridview in C#, WPF

    - by Will
    Hi, I am trying to retrieve data from a Gridview that I have created in XAML. <ListView Name="chartListView" selectionChanged="chartListView_SelectionChanged"> <ListView.View> <GridView> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="250"/> <GridViewColumn Header="Type" DisplayMemberBinding="{Binding Type}" Width="60"/> <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" Width="100"/> </GridView> </ListView.View> </ListView> I have seen some code like this :- GridViewRow row = GridView1.SelectedRow; TextBox2.Text = row.Cells[2].Text; However my problem is that my GridView is created in XAML, and is not named, ie I cannot (or do not know how to) create a reference to 'gridview1', and therefore cannot access objects within it. Can I name or create a reference to my gridview either from c# or XAML so I can use the above code? Secondly, can I then access the array elements by name instead of index, something like :- TextBox2.Text = row.Cells["ID"].Text Thanks for any help.

    Read the article

  • Bind Command to MenuItem

    - by Neir0
    Hi I have ListView and i am trying to bind command to ContextMenu of ListView. <ListView x:Name="listView1" ItemsSource="{Binding Path=Persons}"> <ListView.Resources> <ContextMenu x:Key="ItemContextMenu"> <MenuItem Header="Add" /> <MenuItem Header="Edit"/> <Separator/> <MenuItem Header="Delete" Command="{Binding Msg}" /> </ContextMenu> </ListView.Resources> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <!--<EventSetter Event="PreviewMouseLeftButtonDown" />--><!--Handler="OnListViewItem_PreviewMouseLeftButtonDown" />--> <Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}"/> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> </Style> </ListView.ItemContainerStyle> <ListView.View> <GridView> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" /> <GridViewColumn Header="Sur Name" DisplayMemberBinding="{Binding Path=SurName}" /> <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}" /> </GridView> </ListView.View> </ListView> <Button Content="Message" Command="{Binding Msg}" /> Binding to Button works well but when i click to delete item in ContextMenu, command is not working! Why?

    Read the article

  • WPF ListView GridView DisplayMemberBinding Center alignin content

    - by Bigginn
    I'm trying to center align data in a ListView/Gridview where I use DisplayMemberBinding. This is (partially) how my gridview looks: <ListView> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn DisplayMemberBinding="{Binding Path=Timi}" Width="Auto"> <GridViewColumnHeader Content="Tími" Click="GridViewColumnHeader_Click" ></GridViewColumnHeader> </GridViewColumn> </GridView.Columns> </GridView> </ListView.View> </ListView> I tried to use CellTemplate like explained on this page http://msdn.microsoft.com/en-us/library/system.windows.controls.gridviewcolumn.celltemplate.aspx but it didn't work and then later I read somewhere that one should never use cellTemplate and DisplayMemberBinding together. So the question is : How do I center the gridview data when I use DisplayMemberBinding to bind the data to the gridview? Thanks in advance.

    Read the article

  • wpf display staggered content

    - by Chris Cap
    I am trying to display a rather dynamic list of data in WPF. I have essentially a LineItem class that contains a list of strings and a line type. The line type separates different categories of line items. All line items with the same type should be displayed the same and their data should line up. For example, this list will contain an order summary. And the there will be a line type that represents something with a width and height. The width and height must line up vertically. However, there may be other line types that don't have to line up vertically. I want to produce a table similar to what you see below: ------------------------------------------------------------------ | some content here | some more content here | last content here | |----------------------------------------------------------------| | some content here | | last content here | |----------------------------------------------------------------| | spanning content that is longer then most | last content here | |----------------------------------------------------------------| | some content that can span a really long distance | ------------------------------------------------------------------ I attempted to do this by creating ListView with a single column that had a datatemplate that contained a grid with a fixed number of fields and then bind to the Colspan value. Unfortunately, this didn't work. I ended up with incorrect or overlapping content anytime I tried to do a column span. Here's the XAML I was working with <ListView ItemsSource="{Binding}" > <ListView.View> <GridView> <GridViewColumn Header="Content"> <GridViewColumn.CellTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Grid.ColumnSpan="{Binding Path=Tokens[0].ColumnSpan}" Text="{Binding Path=Tokens[0].Content}" ></TextBlock> <TextBlock Grid.Column="1" Grid.ColumnSpan="{Binding Path=Tokens[1].ColumnSpan}" Text="{Binding Path=Tokens[1].Content}" ></TextBlock> <TextBlock Grid.Column="2" Text="{Binding Path=Tokens[2].Content}"></TextBlock> </Grid> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> And here's the classes I was binding to public class DisplayLine { public LineType Linetype { get; set; } public List<Token> Tokens { get; set; } public DisplayLine() { Tokens = new List<Token>(); } } public class Token { public string Content { get; set; } public bool IsEmpty { get { return string.IsNullOrEmpty(Content); } } public int ColumnSpan { get; set; } public Token() { ColumnSpan = 1; } } Does anyone have any suggestions of maybe a way of making this work. I may be taking the wrong approach. I'm trying to avoid any solutions where I explcitily build something in the code behind as I'm using the MVVM pattern so it has to be something that I can bind from exposed through the controller. My intial plan was to create a factory and separate classes that display the data differently based on type. However, I'm struggling coming up with a strategy for this using MVVM as I really can't just build something and display it. I have toyed with the idea of making some kind of UI service class that is injected, but it would still require some pretty detailed UI information from the controller to do it's work.

    Read the article

  • Changing color of HighlighBrushKey in XAML

    - by phil
    Hi, I have the following problem. The background color in a ListView is set LightGreen or White, whether a boolflag is true or false. Example Screen Window1.xaml: <Window.Resources> <Style TargetType="{x:Type ListViewItem}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=BoolFlag}" Value="True"> <Setter Property="Background" Value="LightGreen" /> </DataTrigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel> <ListView ItemsSource="{Binding Path=Personen}" SelectionMode="Single" SelectionChanged="ListViewSelectionChanged"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding Path=Vorname}" Header="Vorname" /> <GridViewColumn DisplayMemberBinding="{Binding Path=Nachname}" Header="Nachname" /> <GridViewColumn DisplayMemberBinding="{Binding Path=Alter}" Header="Alter" /> <GridViewColumn DisplayMemberBinding="{Binding Path=BoolFlag}" Header="BoolFlag" /> </GridView> </ListView.View> </ListView> </StackPanel> Window1.xaml.cs: public partial class Window1 : Window { private IList<Person> _personen = new List<Person>(); public Window1() { _personen.Add(new Person { Vorname = "Max", Nachname = "Mustermann", Alter = 18, BoolFlag = false, }); _personen.Add(new Person { Vorname = "Karl", Nachname = "Mayer", Alter = 27, BoolFlag = true, }); _personen.Add(new Person { Vorname = "Josef", Nachname = "Huber", Alter = 38, BoolFlag = false, }); DataContext = this; InitializeComponent(); } public IList<Person> Personen { get { return _personen; } } private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { Person person = e.AddedItems[0] as Person; if (person != null) { if (person.BoolFlag) { this.Resources[SystemColors.HighlightBrushKey] = Brushes.Green; } else { this.Resources[SystemColors.HighlightBrushKey] = Brushes.RoyalBlue; } } } } Person.cs: public class Person { public string Vorname { get; set; } public string Nachname { get; set; } public int Alter { get; set; } public bool BoolFlag { get; set; } } Now I want to set the highlight color of the selected item, depending on the boolflag. In Code-Behind I do this with: private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e) { Person person = e.AddedItems[0] as Person; if (person != null) { if (person.BoolFlag) { this.Resources[SystemColors.HighlightBrushKey] = Brushes.Green; } else { this.Resources[SystemColors.HighlightBrushKey] = Brushes.RoyalBlue; } } } } This works fine, but now I want to define the code above in the XAML-file. With <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green" /> I can overwrite the default-value. However, it works, but the color is set to Green for all selected items. I have tried different ways to switch the color of HighlightBrushKey between Green and Blue in XAML, depending on the boolflag, but I didn't succeed. May you can help me and give me some examples?

    Read the article

  • WPF - List View Row Index and Validation

    - by abhishek
    Hi, I have a ListView with TextBoxes in second column. I want to validate that my text box does not contain a number if the third column(data_type) is "Text". I am unable to do the validation. I tried a few approaches. In one approach I try to handle the MouseDown event and am trying to get the Row number so that I can get the data_type value of that row. I want to us this value in the Validate method. I have been struggling for a week now. Would appreciate if anybody could help. <ControlTemplate x:Key="validationTemplate"> <DockPanel> <TextBlock Foreground="Red" FontSize="20">!</TextBlock> <AdornedElementPlaceholder/> </DockPanel> </ControlTemplate> <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> </Style> <DataTemplate x:Key="textTemplate"> <TextBox HorizontalAlignment= "Stretch" IsEnabled="{Binding XPath=./@isenabled}" Validation.ErrorTemplate="{StaticResource validationTemplate}" Style="{StaticResource textBoxInError}"> <TextBox.Text> <Binding XPath="./@value" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <local:TextBoxMinMaxValidation> <local:TextBoxMinMaxValidation.DataType> <local:DataTypeCheck Datatype="{Binding Source={StaticResource dataProvider}, XPath='/[@id=CustomerServiceQueueName]'}"/> </local:TextBoxMinMaxValidation.DataType> <local:TextBoxMinMaxValidation.ValidRange> <local:Int32RangeChecker Minimum="{Binding Source={StaticResource dataProvider}, XPath=./@min}" Maximum="{Binding Source={StaticResource dataProvider}, XPath=./@max}"/> </local:TextBoxMinMaxValidation.ValidRange> </local:TextBoxMinMaxValidation> </Binding.ValidationRules> </Binding > </TextBox.Text> </TextBox> </DataTemplate> <DataTemplate x:Key="dropDownTemplate"> <ComboBox Name="cmbBox" HorizontalAlignment="Stretch" SelectedIndex="{Binding XPath=./@value}" ItemsSource="{Binding XPath=.//OPTION/@value}" IsEnabled="{Binding XPath=./@isenabled}" /> </DataTemplate> <DataTemplate x:Key="booldropDownTemplate"> <ComboBox Name="cmbBox" HorizontalAlignment="Stretch" SelectedIndex="{Binding XPath=./@value, Converter={StaticResource boolconvert}}"> <ComboBoxItem>True</ComboBoxItem> <ComboBoxItem>False</ComboBoxItem> </ComboBox> </DataTemplate> <local:ControlTemplateSelector x:Key="myControlTemplateSelector"/> <Style x:Key="StretchedContainerStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="Template" Value="{DynamicResource ListBoxItemControlTemplate1}"/> </Style> <ControlTemplate x:Key="ListBoxItemControlTemplate1" TargetType="{x:Type ListBoxItem}"> <Border SnapsToDevicePixels="true" x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" Padding="{TemplateBinding Padding}" BorderThickness="0,0.5,0,0.5"> <GridViewRowPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> </ControlTemplate> <Style x:Key="CustomHeaderStyle" TargetType="{x:Type GridViewColumnHeader}"> <Setter Property="Background" Value="LightGray" /> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="FontFamily" Value="Arial"/> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="Padding" Value="2,0,2,0"/> </Style> </UserControl.Resources> <Grid x:Name="GridViewControl" Height="Auto"> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="34"/> </Grid.RowDefinitions> <ListView x:Name="ListViewControl" Grid.Row="0" ItemContainerStyle="{DynamicResource StretchedContainerStyle}" ItemTemplateSelector="{DynamicResource myControlTemplateSelector}" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Source={StaticResource dataProvider}, XPath=//CONFIGURATION}"> <ListView.View > <GridView > <GridViewColumn Header="ID" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@id}"/> <GridViewColumn Header="VALUE" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" CellTemplateSelector="{DynamicResource myControlTemplateSelector}" /> <GridViewColumn Header="DATATYPE" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@data_type}"/> <GridViewColumn Header="DESCRIPTION" HeaderContainerStyle="{StaticResource CustomHeaderStyle}" DisplayMemberBinding="{Binding XPath=./@description}" Width="{Binding ElementName=ListViewControl, Path=ActualWidth}"/> </GridView> </ListView.View> </ListView> <StackPanel Grid.Row="1"> <Button Grid.Row="1" HorizontalAlignment="Stretch" Height="34" HorizontalContentAlignment="Stretch" > <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center" Orientation="Horizontal" FlowDirection="RightToLeft" Height="30"> <Button Grid.Row="1" Content ="Apply" Padding="0,0,0,0 " Margin="6,2,0,2" Name="btn_Apply" HorizontalAlignment="Right" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Width="132" IsTabStop="True" Click="btn_ApplyClick" Height="24" /> </StackPanel > </Button> </StackPanel > </Grid>

    Read the article

  • Assign binding path at runtime in WPF DataTemplate

    - by Abiel
    I am writing a WPF program in C# in which I have a ListView for which the columns will be populated at runtime. I would like to use a custom DataTemplate for the GridViewColumn objects in the ListView. In the examples I have seen where the number of columns is fixed in advance, a custom DataTemplate is often created using something like the XAML below. <DataTemplate x:Key="someKey"> <TextBlock Text="{Binding Path=FirstName}" /> </DataTemplate> This DataTemplate could also later be assigned to GridViewColumn.CellTemplate in the code-behind by calling FindResource("someKey"). However, this alone is of no use to me, because in this example the Path element is fixed to FirstName. Really I need something where I can set the Path in code. It is my impression that something along these lines may be possible if XamlReader is used, but I'm not sure how in practice I would do this. Any solutions are greatly appreciated.

    Read the article

  • DataBinding to ListView

    - by Neir0
    Hi, I have a class public class Foo { public List<string> list1 { get; set;} public List<string> list2 { get; set; } public string url; } and a ListView with two columns <ListView Name="listview" ItemsSource="{Binding}"> <ListView.View> <GridView> <GridViewColumn Header="list1" DisplayMemberBinding="{Binding Path=list1}" /> <GridViewColumn Header="list2" DisplayMemberBinding="{Binding Path=list2}" /> </GridView> </ListView.View> </ListView> How i can to bind instance of Foo class to ListView? Here i set DataContext listview.DataContext = new Foo() { list1 = new[] { "dsfasd", "asdfasdf", "asdf", "asdfasd" }.ToList(), list2 = new[] { "dsfasd", "asdfasdf", "asdf", "asdfasd" }.ToList() }; But it's not work.

    Read the article

  • WPF customer control and direct content support

    - by Mmarquee
    I am fairly new to WPF, and am a bit stuck, so any help would be appreciated. I am trying to write WPF custom control that encapsulates several elements of functionality that I already having working (i.e sorting, filtering, standard menus, etc.), but in a nice neat package to avoid repetition. Anyway I have created the custom control (based on control), and then have the following in the Generic.Xaml <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Controls.ListViewExtended"> <Style TargetType="{x:Type local:ListViewExtended}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:ListViewExtended}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <ListView> <ListView.View> <GridView> <!-- Content goes here --> </GridView> </ListView.View> </ListView> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> When I try to add GridViewColumns (or any control really), as below ... <elv:ListViewExtended> <GridView> <GridViewColumn Width="140" Header="Column 1" /> <GridViewColumn Width="140" Header="Column 2" /> <GridViewColumn Width="140" Header="Column 3" /> </GridView> </elv:ListViewExtended> I get the "... does not support direct content" error. I have created a dependancy property (again below) that allows the adding of GridView, but it still doesn't work. public static DependencyProperty GridViewProperty; public static string GridViewHeader(DependencyObject target) { return (string)target.GetValue(GridViewProperty); } public static void GridViewHeader(DependencyObject target, string value) { target.SetValue(GridViewProperty, value); } Thanks in advance

    Read the article

  • How can I access the ListViewItems of a WPF ListView?

    - by David Schmitt
    Within an event, I'd like to put the focus on a specific TextBox within the ListViewItem's template. The XAML looks like this: <ListView x:Name="myList" ItemsSource="{Binding SomeList}"> <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <!-- Focus this! --> <TextBox x:Name="myBox"/> I've tried the following in the code behind: (myList.FindName("myBox") as TextBox).Focus(); but I seem to have misunderstood the FindName() docs, because it returns null. Also the ListView.Items doesn't help, because that (of course) contains my bound business objects and no ListViewItems. Neither does myList.ItemContainerGenerator.ContainerFromItem(item), which also returns null.

    Read the article

  • Adding Rows to Gridview without using databind

    - by powertex
    Hello, I have a gridview inside of a listview predefined in the xaml: .... <ListView x:Name="listPriority" IsSynchronizedWithCurrentItem="True" Margin="0,30,0,4" BorderThickness="0,0,0,0"> <ListView.View> <GridView> <GridViewColumn x:Name="grvPriorityColumn" Width="140" Header="Priority" /> <GridViewColumn x:Name="grvMessage" Width="250" Header="Message" /> </GridView> </ListView.View> .... I have an array containing data that needs to go into the "grvPriorityColumn" and "grvMessage". How do add this data to the gridview without using databinding?

    Read the article

< Previous Page | 1 2 3  | Next Page >