Reputation: 650
I am using WPF Xceed.Wpf.Toolkit.PropertyGrid
to show properties of my object for user to edit.
My class property is as shown below:
private double height;
[Browsable(true)]
[RefreshProperties(RefreshProperties.All)]
public double Height
{
get
{
return height;
}
set
{
bodymass = height * 10;//Some other property
_height= value;
}
}
For each key press, set() is called and the grid row is loosing its focus due to RefreshProperties.All
. Due to that, it is not possible to continuously type values to the grid row.
Is it possible to keep focus on the same property I was type in?
Or at least, it there a way to instruct the set() to be called only when user click enter/ loose focus?
Upvotes: 0
Views: 607
Reputation: 169280
Get rid of the RefreshProperties
attribute, implement the INotifyPropertyChanged
interface and raise the PropertyChanged
event for all properties that you want to refresh in the setter of the Height
property:
public class MyObject : INotifyPropertyChanged
{
private double height;
[Browsable(true)]
public double Height
{
get
{
return height;
}
set
{
height = value;
Test = height.ToString(); //this refreshes Test
}
}
private string _test;
public string Test
{
get { return _test; }
set { _test = value; NotifyPropertyChanged(); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
<xctk:PropertyGrid x:Name="_propertyGrid" Width="450" Margin="10" AutoGenerateProperties="False">
<xctk:PropertyGrid.PropertyDefinitions>
<xctk:PropertyDefinition TargetProperties="Height" />
<xctk:PropertyDefinition TargetProperties="Test" />
</xctk:PropertyGrid.PropertyDefinitions>
</xctk:PropertyGrid>
Upvotes: 1