I've got several times the question, but never figured out how to properly resolve it.
I've an object, SensorOrientation
, which is composed of an float and a boolean:
public class SensorOrientation{
public float? RadialAngle {
get{
//Getting from backingField
}
set{
//Setting the backingField
//Notifying
}
}
public bool IsAxial {
get{
//Getting from backingField
}
set{
//Setting the backingField
//Notifying
}
}
}
In my ViewModel, I've one SensorOrientation
property, and one other property, which is a basic ViewModel(I've a graph with 9 position, and I've to select the one that is the closest to the custom value in the RadialAngle).
So I've created a enum:
public enum OrientationEditorDirection
{
Unknown,
Center,
Top,
TopRight,
Right,
BottomRight,
Bottom,
BottomLeft,
Left,
TopLeft
}
So in my ViewModel, I want to update this when the value of "RadialAngle" or "IsAxial" has changed:
public class ViewModel{
public SensorOrientation Orientation {
get{
//Getting from backingField
}
set{
//Setting the backingField
//Notifying
}
}
public OrientationEditorDirection Direction {
get=> CallToTheMethodThatComputeTheCorrectDirection();
set => CallToTheMethodThatUpdateTheSensorOrientationValue(value);
}
}
In the xaml of this ViewModel, I've 2 differents sub-controls, one that display the direction, one that is a custom field editing the exact value of the ? Orientation.RadialAngle
(when the guy clicks on Center
(which is equal to Axial), then the custom textbox is hidden).
<local:OrientationEditor SelectedDirection="{Binding Direction}" />
<angleEditor:AngleEditor Angle="{Binding Orientation.Angle }"/>
The issue is that since my AngleEditor
is bound(and has to be bound, it is used in some other case), on a sub-sub-property, I don't see when I could raise the property changed for the Direction.
The best I could do as of today, was that in my ViewModel, when I set a new "Orientation", I register on the PropertyChanged
event manually, and when something change I update the Direction. But I find that quite ugly not very WPFish.
Any idea how I can do this better?