So I'm working on an assignment where we're supposed to make a Mii Maker in C# and WPF, and I've got everything working but the caviat is that we're supposed to use as little code as possible, and use binding instead. I've created a ValueConverter for a few of the other parts, and they worked fine, but when I try to update the point of an ArcSegment using a MultiBind (I need a few values to keep everything centered) the point stays stationary.
Here's the working code without the multi-bind:
XAML:
<Path Stroke="Black" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure x:Name="LeftMouthCorner" StartPoint="221,190" IsClosed="False">
<ArcSegment x:Name="RightMouthCorner" Point="291,190" Size="{Binding ElementName=MouthHappinessSlider, Path=Value, Converter={StaticResource HappinessConverter}}">
</ArcSegment>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
C#:
private void MouthWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
MouthWidthLabel.Content = String.Format("Mouth Width: {0}", MouthWidthSlider.Value);
if (MouthWidthSlider != null && MouthHeightSlider != null && HeadYPosSlider != null)
{
LeftMouthCorner.StartPoint = new Point(((myCanvas.ActualWidth / 2) - MouthWidthSlider.Value), (HeadYPosSlider.Value + MouthHeightSlider.Value));
RightMouthCorner.Point = new Point(((myCanvas.ActualWidth / 2) + MouthWidthSlider.Value), (HeadYPosSlider.Value + MouthHeightSlider.Value));
}
}
I want to remove that method and extract it into a MultiValueConverter (or two, since the arc has two points), and update the Point directly instead of using the value_Changed method, like so:
XAML:
<Path Stroke="Black" StrokeThickness="3">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure x:Name="LeftMouthCorner" StartPoint="221,190" IsClosed="False">
<ArcSegment x:Name="RightMouthCorner" Size="{Binding ElementName=MouthHappinessSlider, Path=Value, Converter={StaticResource HappinessConverter}}">
<ArcSegment.Point>
<MultiBinding Converter="{StaticResource RMCConverter}" UpdateSourceTrigger="PropertyChanged">
<Binding ElementName="HeadYPosSlider" Path="Value" />
<Binding ElementName="MouthHeightSlider" Path="Value" />
<Binding ElementName="MouthWidthSlider" Path="Value" />
<Binding ElementName="myCanvas" Path="Width" />
</MultiBinding>
</ArcSegment.Point>
</ArcSegment>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
C# MultiValueConverter:
public class RMCConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//HYP / MHS / MWS / mCW
var hyp = values[0];
var mhs = values[1];
var mws = values[2];
var mcw = values[3];
double HeadYPos = (double)hyp,
MouthHeight = (double)mhs,
MouthWidth = (double)mws,
CanvasWidth = (double)mcw;
return new Point(((CanvasWidth / 2) + MouthWidth), (HeadYPos + MouthHeight));
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Does anybody know how to do it this way? When I print out the values the MultiBind receives everything's correct, and I've tried returning both the new Point() and a formatted String, but nothing seems to work.
Further information: There are no build errors, I've got the MultiValueConverter in the Window.Resources tag, all the values getting passed into the multibind are from sliders, and they're all correct when I returned the string to a label using the same xaml code for the multibind (like so):
<Label>
<Content>
<MultiBind-Code from above goes here>
</Content>
</Label>
Do I need to keep the working code and just deal with it, or is there a way to update the ArcSegment's point with the MultiBind?