Telerik Forums
UI for WPF Forum
0 answers
15 views
moved to ticket
n/a
Top achievements
Rank 1
 updated question on 26 Jan 2024
0 answers
25 views
I have a class (ItemTree Parent) bound to a RadPropertyGrid. The class also contains a List of it's own type (List<ItemTree> Children). Is it possible to apply the same PropertyDefinitions for both the parent and children?
Will
Top achievements
Rank 1
Iron
 asked on 10 Nov 2023
2 answers
37 views

[edit: I meant "Modal" Editor and not "Model" editor in the title but I can't update]

Hi,

 

as I know you can use a custom modal editor with an Editor attribute that is declared on a property. Is it possible to use a modal editor with a programmatic approach with PropertyDefinition? I have a dynamic class where I do not have the possibility to declare attributes on properties. On the PropertyDefinition class there is an EditorTemplate property. I managed to use this. But only "in cell" and not modal. Is that possible?

Best regards,

Oliver

OBollmann
Top achievements
Rank 2
Iron
 answered on 20 Mar 2023
1 answer
89 views

Hi

I have a RadPropertyGrid, being defined as:

       <telerik:RadPropertyGrid Item="{Binding ObjectBound, Mode=OneWay}" Width="300" Name="propertyGrid2"
                                 Grid.Column="1"
                                 VerticalAlignment="Stretch"
                                 VerticalContentAlignment="Stretch"
                                 NestedPropertiesVisibility="Visible"
                                 AutoGeneratePropertyDefinitions="True"
                                 SelectionMode="Multiple"
                                 PropertySetMode="Intersection"
                                 telerik:PropertySet.ShouldAddNullForNonMatchingValues="True"

 

where I would like to bind 0...n items

 

Let's say all of those items belong to the class Car

 

  public class CarEngine
    {
        public int PowerKW { get; set; }
        public int DisplacementCCM { get; set; }

    }
    public class Car
    {
        public Car()
        {
            Engine = new ();
        }
        public string Manufacturer { get; set; }
        public string Color { get; set; }
        public CarEngine Engine { get; set; }

    }

In the code behind I have a property to bind to the PropertyGrid

 

public object ObjectBound
        {
            get;
            set;
        }

and will create the items like this:

 

  Car c = new Car();
            c.Manufacturer = "Honda";
            c.Engine.PowerKW = 110;
            c.Engine.DisplacementCCM = 1799;
            c.Color = "black";


            Car c2 = new Car();
            c2.Manufacturer = "BMW";
            c2.Engine.DisplacementCCM = 2199;
            c2.Engine.PowerKW = 150;
            c2.Color = "black";

            List<Car> list = new();
            list.Add(c);
            list.Add(c2);

now first, I will bind just one car instance to the RadPropertyGrid:

            this.ObjectBound = c;

Here I can expand the nested engine instance and can write to each field which is absolutety perfect!

Then we have a second use case where I would like to bind to the list with two cars and get their common attributes while differerent properties will be displayed empty:

      this.ObjectBound = list;

Therefore I had choosen "Intersection" for the propertysetmode of the RadPropertyGrid

For the primitive Attributes Color (shared between both cars) and Manufacturer (different) that will work just fine. 

 

 

But as one can see the nested Attribute "Engine" cannot be set as it not able to be expanded! I'd like to set e.g. a common displacement for both of the two cars. How can I realize such a behaviour as it is required from business?

 

thanks!

         
Stenly
Telerik team
 answered on 01 Mar 2023
0 answers
74 views

Hi,

I have a window that has a RadPropertyGrid and UserControl that contains five buttons. I want to make the screen full while clicking on maximize button. Now as I have fixed height and width. Maximize button is not working. Can you please help me out.

<Window x:Class="WPF.Views.NoteEdit"
        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:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        xmlns:customcontrol="clr-namespace:WPF.CustomControl"
        xmlns:local="clr-namespace:WPF.Views"
        mc:Ignorable="d"
        x:Name="vwNoteEditWindow"
        Title="NoteEdit" Height="680" Width="750">
    <Grid Height="564" VerticalAlignment="Top" >
        <Grid HorizontalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <telerik:RadLayoutControl
                Name="PropertyGridContainer"
                Margin="5"
                VerticalAlignment="Top"
                HorizontalAlignment="Center"              
                BorderThickness="0"
                Orientation="Vertical">
            </telerik:RadLayoutControl>
        </Grid>

        <Grid VerticalAlignment="Bottom">
            <customcontrol:RadPropertyWindowButtons x:Name="ucPropertyButtons" Height="44" VerticalAlignment="Top" HorizontalAlignment="Center" Loaded="RadPropertyWindowButtons_Loaded" CustomCancelClick="btn_Cancel_Click" CustomExitClick="btn_Exit_Click" />
        </Grid>
    </Grid>
</Window>

 

User control :

<UserControl x:Class="WPF.CustomControl.RadPropertyWindowButtons"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:NPTS_WPF.CustomControl"
             xmlns:fa="http://schemas.fontawesome.io/icons/"
             mc:Ignorable="d" 
             d:DesignHeight="45" d:DesignWidth="700">
    <Grid>
        <Grid Uid="radpropertybuttons" Height="39" VerticalAlignment="Bottom" Margin="74,0,-108,0">
            <Button x:Name="btnNormal_Cancel" Margin="0,0,600,10" HorizontalAlignment="Right" Width="80" Height="25" VerticalAlignment="Bottom">
            </Button>

            <Button x:Name="btnNormal_Accept" Margin="0,0,500,10" HorizontalAlignment="Right" Width="80" Height="25" VerticalAlignment="Bottom">
            </Button>

            <Button x:Name="btnNormal_Imperial"  Margin="0,0,370,10" HorizontalAlignment="Right" Width="110" Height="25" VerticalAlignment="Bottom">
            </Button>

            <Button x:Name="btnNormal_Exit" Margin="0,0,270,10" HorizontalAlignment="Right" Width="80" Height="25" VerticalAlignment="Bottom">
            </Button>

            <Button x:Name="btnNormal_Clone" Margin="0,0,170,10" HorizontalAlignment="Right" Width="80" Height="25" VerticalAlignment="Bottom">

            </Button>
        </Grid>

    </Grid>
</UserControl>
Sudeshna
Top achievements
Rank 1
 asked on 06 Feb 2023
0 answers
27 views
Never mind. I figured out the issue 
Sudeshna
Top achievements
Rank 1
 updated question on 26 Jan 2023
0 answers
55 views

Hi.

I have the following RadPropertyGrid:

XAML:

<Grid
        behaviors:CalloutTagBehavior.CalloutTag="F6C90D8E-9F1C-4372-87D0-17B40EE1E462"
        IsEnabled="{Binding StateDispatcher.EnvironmentState,
                            Converter={converters:ComparisonConverter},
                            ConverterParameter={x:Static runtime:EnvironmentState.Design}}">
        <telerik:RadPropertyGrid
            x:Name="RadPropertyGrid"
            telerik:PropertySet.ShouldAddNullForNonMatchingValues="True"
            AutoGeneratingPropertyDefinition="RadPropertyGrid_OnAutoGeneratingPropertyDefinition"
            EditEnded="RadPropertyGrid_OnEditEnded"
            EditMode="Single"
            FieldIndicatorVisibility="Collapsed"
            IsGrouped="False"
            Item="{Binding SelectedObject}"
            LabelColumnWidth="0.8*"
            Loaded="RadPropertyGrid_OnLoaded"
            PropertySetMode="None"
            RenderMode="Flat">
            <telerik:RadPropertyGrid.GroupStyle>
                <Style TargetType="telerik:RadToggleButton">
                    <Setter Property="Margin" Value="0,0,15,0" />
                </Style>
            </telerik:RadPropertyGrid.GroupStyle>
        </telerik:RadPropertyGrid>
    </Grid>

CodeBehinde:

public partial class PropertyGridPaneUserControl : UserControl
{
    public PropertyGridPaneUserControl(IEventAggregator eventAggregator)
    {
        if (eventAggregator == null) throw new ArgumentNullException(nameof(eventAggregator));
        InitializeComponent();
        eventAggregator.Register<RefreshPropertyGridMessage>(this, RefreshPropertyGridMessageHandler);
    }

    private void RefreshPropertyGridMessageHandler(RefreshPropertyGridMessage message)
    {
        RadPropertyGrid.ReloadData();
    }

    private void RadPropertyGrid_OnAutoGeneratingPropertyDefinition(object? sender, AutoGeneratingPropertyDefinitionEventArgs e)
    {
        ((Binding)e.PropertyDefinition.Binding).ValidatesOnExceptions = true;
    }

    private void RadPropertyGrid_OnLoaded(object sender, RoutedEventArgs e)
    {
        var virtualizingStackPanel = RadPropertyGrid
            .ChildrenOfType<VirtualizingStackPanel>().FirstOrDefault();
        if (virtualizingStackPanel != null)
        {
            virtualizingStackPanel.ScrollOwner.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
        }
    }

    private void RadPropertyGrid_OnEditEnded(object? sender, PropertyGridEditEndedEventArgs e)
    {
        if (e.EditAction != PropertyGridEditEndedAction.Commit ||
            Equals(e.NewValue, e.OldValue) ||
            DataContext is not PropertyGridViewModel {SelectedObjects: { }} propertyGridViewModel) return;

        ItemPropertyInfo sourceProperty = e.EditedPropertyDefinition.SourceProperty;

        foreach (var selectedObject in propertyGridViewModel.SelectedObjects)
        {
            if (selectedObject == e.EditedPropertyDefinition.Instance) continue;

            PropertyInfo? property = selectedObject.GetType()
                .GetProperty(sourceProperty.Name, sourceProperty.PropertyType);

            if (property != null)
            {
                property.SetValue(selectedObject, e.NewValue);
            }
        }
    }
}

And it worked fine up to a certain point. The problem occurs when processing an object with the ObservableCollection property of the following type:

public class A
{
    public ObservableCollection<object> Collection { get; }
}

My task is to perform asynchronous addition of elements to a nested collection. If I didn't open the CollectionEditor in the UI, then the addition happens without problems. But if you open CollectionEditor in UI at least once, InvalidOperationnException is generated when adding asynchronously: The calling thread cannot access this object because a different thread owns it.  Stack trace part:

 at System.Windows.Threading.Dispatcher.VerifyAccess()
  at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
  at System.Windows.Controls.Panel.get_IsItemsHost()
  at System.Windows.Controls.ItemsControl.GetItemsOwnerInternal(DependencyObject element, ItemsControl& itemsControl)
  at System.Windows.Controls.Panel.VerifyBoundState()
  at System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)
  at System.Windows.Controls.ItemContainerGenerator.OnItemAdded(Object item, Int32 index)
  at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
  at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
  at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
  at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
  at System.Windows.WeakEventManager.ListenerList`1.DeliverEvent(Object sender, EventArgs e, Type managerType)
  at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
  at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
  at MS.Internal.Data.CollectionViewProxy._OnViewChanged(Object sender, NotifyCollectionChangedEventArgs args)
  at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
  at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChangedWithAdjustedArgs(NotifyCollectionChangedEventArgs originalArguments, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
  at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args)
  at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
  at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
  at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
  at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)

At the same time, an exception occurs even if in Rad PropertyGrid.Item set another instance of the object or null. I would like to know how to correct this misunderstanding

Mikola
Top achievements
Rank 1
 asked on 29 Sep 2022
2 answers
80 views

Hello,

I am experiencing the same issue, that "Guy" has mentioned in his thread:

Link to question

However, the topic is discontinued. So the issue is, that when i use classic field style, everything looks good. My object has 4 properties, and the event FieldLoaded is called 4 times - see counter at the bottom.

However, when i apply FieldStyle (in my case FieldStyle="{StaticResource PropertyGridFieldStyleCustom}") to make property name appear over editor instead of on the left on it, the fieldloaded event is called 8 times - twice for each property.

I am attaching my solution where You can see the example im referring to. Is there something im doing wrong, or it may be a RadPropertyGrid bug?

Thanks for any help.

Andrzej
Top achievements
Rank 1
Iron
 answered on 23 Sep 2022
2 answers
109 views
Hello. How to make the field fill the width of the container and not stretch to fit the text. Two pictures in the attachment. In the second image, the PropertyGrid extends outside the container. 
Stenly
Telerik team
 answered on 14 Jan 2022
0 answers
112 views

I'm trying to be able to expand nested properties programmatically. Specifically, I have two RadPropertyGrids next to each other for the purpose of comparing two objects and if I expand a nested property on one object I'd like to have the nested property on the other object auto-expand to keep the two views in sync. I'm trying to accomplish this by binding the IsExpanded property of the two property definitions together. This only partially works. When you click the + button to expand a nested property, the corresponding property on the other object disappears. If you click again the corresponding property reappears and they are both collapsed. If you click a third time they both expand as expected. It works correctly from then on. Just the first time is the problem.

This problem even occurs if you remove the RightGrid and just use the button to programmatically change the IsExpanded field. On the first click the property disappears completely. Subsequent clicks work as expected. If you click the + icon on the property itself it works fine.

I need to be able to set PropertyDefinition.IsExpanded programmatically at some point after the PropertyGrid is displayed. Setting it during AutoGeneratingPropertyDefinition is not an option.

I'm using version 2021.3.1109.

Andrew
Top achievements
Rank 1
 asked on 15 Nov 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?