Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
270
How to add an item programmatically
posted

Hello,

I try to add a item programmatically to the XamPropertyGrid. The Source is a ListItem witch will be generated dynamically. Each Item contains a Headernam, Value, Type of the value and a readonly flag. I want to display it like this:

Headername | Value
Headername |Value
...
...

How can I do this in the right way?

I added some lines with a little sample. The wanted output is
Name | Frank

Sourecode:

XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication6"
        xmlns:ig="http://schemas.infragistics.com/xaml" x:Class="WpfApplication6.MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ig:XamPropertyGrid x:Name="propgrid"/>
    </Grid>
</Window>

Codebehind:

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); TransferObject frank = new TransferObject() { HeaderName = "Name", Value = "Frank", Typ = typeof(string), Readonly = false }; this.propgrid.SelectedObject = frank; } } public class TransferObject { public string HeaderName { get; set; } public object Value { get; set; } public Type Typ { get; set; } public bool Readonly { get; set; } }

Parents
  • 34830
    Offline posted

    Hello Jan,

    Thank you for your post.

    Unfortunately, I'm not entirely sure you are trying to use the XamPropertyGrid in the way that it was designed. The XamPropertyGrid was designed to take a selected object and display all of the properties that exist on that object so that they can be edited. When you say you are looking to add multiple items to the XamPropertyGrid and display them in a way similar to the below, I'm not sure you will be able to achieve this requirement you are looking for with the XamPropertyGrid:

    HeaderName | Value
    HeaderName | Value

    It may be possible for you to do this with a single record, if you include the default template for PropertyGridPropertyItemView, which is found in the generic.shared.xaml file commonly found at the following directory: C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\PropertyGrid, and re-bind the TextBlock currently bound to DisplayName to the XamPropertyGrid's SelectedObject.HeaderName. However, this may cause other complications with the XamPropertyGrid, and I would not really recommend going this route.

    My recommendation to you, based on the behavior you are looking to achieve is that you use the XamDataGrid control instead of the XamPropertyGrid. By doing this, you could display your items in a HeaderName and a Value column, rather than trying to modify the XamPropertyGrid to do this. Here is a link to the online documentation about the XamDataGrid: http://help.infragistics.com/doc/WPF/2015.2/CLR4.0/?page=xamDataGrid_Getting_Started_with_xamDataGrid.html. If you would like to proceed this way, please let me know and I may be able to create a sample project for you to demonstrate the above.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

Reply Children