Coder Social home page Coder Social logo

Comments (4)

XceedBoucherS avatar XceedBoucherS commented on July 18, 2024

Hi,

Instead of using the IsExpandingNonPrimitiveTypes, which will make all possible subItem expandable, you can set the
[ExpandableObject()] attribute over the object you want to see as expandable:

<xctk:PropertyGrid Grid.Row="1"
x:Name="_propertyGrid"
Width="450"
MaxHeight="650"
Margin="10"
SelectedObject="{Binding}"
ShowDescriptionByTooltip="True"
IsExpandingNonPrimitiveTypes="False">
</xctk:PropertyGrid>

this.DataContext = new Player() { Infos = new Infos() { FirstName = "Kyle", LastName = "Matheson" }, Infos2 = new Infos2() { ThirdName = "John", FourthName = "Mike" }, Position = "Center" };

public class Player
{
[ExpandableObject()] //Only Infos will be expandable
public Infos Infos { get; set; }

public Infos2 Infos2 { get; set; }

public string Position { get; set; }
}

public class Infos
{
public string FirstName { get; set; }
public string LastName { get; set; }
}

public class Infos2
{
public string ThirdName { get; set; }
public string FourthName { get; set; }
}

from wpftoolkit.

EdoardoNagliati avatar EdoardoNagliati commented on July 18, 2024

Thank's for your answer.

I've another problem: the function ExpandendProperty doesn't work.

In the PropGrid class, I have a property named 'Fondazione' with the attribute 'RefreshProperty.All'. When the refresh is triggered, all properties in the PropertyGrid are collapsed, even if they were not collapsed before. To resolve this issue and maintain the appearance of the PropertyGrid unchanged, I thought about raising an event (OnBeforeFondazioneChanged) before the refresh and saving the expanded properties in a List. Then, after the refresh, the function PropertyValueChanged is called, which should expand each property in the list using ExpandProperty, but this does not work. The list is correctly populated, and it seems that ExpandProperty is specifically what is not working. I made an attempt where instead of calling ExpandProperty I call ExpandAllProperties, and this expands all the properties.

public List ExpandedProp;
public MainWindow()
{
InitializeComponent();
var pGrid=new PropGrid();
pGrid.Fondazione=false;

....
pGrid.svincoloI=new SvincoloI();
pGrid.svincoloJ=new SvincoloJ();
pGrid.armaturaInf=new Armatura();
pGrid.armaturaSup=new Armatura();

pGrid.BeforeFondazioneChanged+=MyCustomEventHandler;

ExpandedProp=new List<PropertyItem>();

this.DataContext = pGrid;

}

private void MyCustomEventHandler(object sender, EventArgs e)
{
foreach (PropertyItem prop in _propertyGrid.Properties)
{
if (prop.IsExpanded==true)
{
ExpandedProp.Add(prop);
}

 }

}

private void _propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
{
foreach (PropertyItem prop in ExpandedProp)
{
_propertyGrid.ExpandProperty(prop.PropertyName.ToString());
}
// _propertyGrid.ExpandAllProperties();
ExpandedProp.Clear();
}

public class PropGrid
{
public event EventHandler BeforeFondazioneChanged;

 private  bool mFondazione;

[Category("Interazione terreno")]
[RefreshProperties(RefreshProperties.All)]
[ReadOnly(false)]
public bool Fondazione
{
get { return mFondazione; }
set
{

    OnBeforeFondazioneChanged();

    mFondazione = value;
    PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this.GetType())["k"];
    ReadOnlyAttribute attribute = (ReadOnlyAttribute)descriptor.Attributes[typeof(ReadOnlyAttribute)];
    var fieldToChange = attribute.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault(a => a.Name.Contains("readonly", StringComparison.OrdinalIgnoreCase));

    fieldToChange.SetValue(attribute, mFondazione ==false);
}

}

....
}

from wpftoolkit.

EdoardoNagliati avatar EdoardoNagliati commented on July 18, 2024

EDIT: I find that works if instead of
_propertyGrid.ExpandProperty(prop.PropertyName)
I use
_propertyGrid.ExpandProperty(prop.DispalyName)

but this raise a Binding failure: IsMiscCategoryLabelHidden

from wpftoolkit.

XceedBoucherS avatar XceedBoucherS commented on July 18, 2024

Hi,
This binding failure is related to the RefreshProperties attribute.
While refreshing, a MultiDataTrigger is validating the grouping and checking for a condition on IsMiscCategoryLabelHidden of a parent PropertyGrid. But the refresh re-creates the groups, and the MultiDataTrigger becomes useless in this situation. Just don`t bother about this warning.

Thanks

from wpftoolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.