Skip to content

Commit

Permalink
Merge pull request #3166 from unoplatform/dev/jela/xbind-convert-issue
Browse files Browse the repository at this point in the history
fix(reg): Use XamlBindingHelper.ConvertValue for TwoWay x:Bind
  • Loading branch information
jeromelaban authored May 15, 2020
2 parents 8acf13b + 68df6f7 commit 900f7dd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ string buildBindBack()
if (propertyPaths.properties.Length == 1)
{
var targetPropertyType = GetXBindPropertyPathType(propertyPaths.properties[0], GetType(dataType));
return $"(___ctx, __value) => {{ if(___ctx is {dataType} ___tctx) {{ {contextFunction} = ({targetPropertyType})({propertyType})__value; }} }}";
return $"(___ctx, __value) => {{ if(___ctx is {dataType} ___tctx) {{ {contextFunction} = ({targetPropertyType})global::Windows.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(typeof({targetPropertyType}), __value); }} }}";
}
else
{
Expand Down Expand Up @@ -2924,7 +2924,7 @@ string buildBindBack()
if (propertyPaths.properties.Length == 1)
{
var targetPropertyType = GetXBindPropertyPathType(propertyPaths.properties[0]);
return $"(___tctx, __value) => {rawFunction} = ({targetPropertyType})({propertyType})__value";
return $"(___tctx, __value) => {rawFunction} = ({targetPropertyType})global::Windows.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(typeof({targetPropertyType}), __value)";
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<Grid>
<Slider x:Name="mySlider"
x:FieldModifier="public"
Value="{x:Bind MyInteger, Mode=TwoWay}"/>
Value="{x:Bind MyInteger, Mode=TwoWay}" />
<TextBlock x:Name="myTextBlock"
x:FieldModifier="public"
Text="{x:Bind MyInteger, Mode=TwoWay}" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
x:FieldModifier="public">
<ContentControl.ContentTemplate>
<DataTemplate x:DataType="local:Binding_TypeMismatch_DataTemplate_Data">
<Slider x:Name="mySlider"
x:FieldModifier="public"
Value="{x:Bind MyInteger, Mode=TwoWay}"/>
<StackPanel>
<Slider x:Name="mySlider"
x:FieldModifier="public"
Value="{x:Bind MyInteger, Mode=TwoWay}" />
<TextBlock x:Name="myTextBlock"
x:FieldModifier="public"
Text="{x:Bind MyInteger, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,18 @@ public void When_TypeMismatch()

SUT.ForceLoaded();

var inner = SUT.FindName("mySlider") as Slider;
var slider = SUT.FindName("mySlider") as Slider;
var textBlock = SUT.FindName("myTextBlock") as TextBlock;

Assert.AreEqual(0.0, inner.Value);
Assert.AreEqual(0.0, slider.Value);
Assert.AreEqual("0", textBlock.Text);
Assert.AreEqual(0, SUT.MyInteger);

inner.Minimum = 10.0;
slider.Minimum = 10.0;

Assert.AreEqual(10.0, inner.Value);
Assert.AreEqual(10.0, slider.Value);
Assert.AreEqual(10, SUT.MyInteger);
Assert.AreEqual("10", textBlock.Text);
}

[TestMethod]
Expand All @@ -624,14 +627,17 @@ public void When_TypeMismatch_DataTemplate()
SUT.ForceLoaded();

var slider = SUT.FindName("mySlider") as Slider;
var textBlock = SUT.FindName("myTextBlock") as TextBlock;

Assert.AreEqual(0.0, slider.Value);
Assert.AreEqual(0, rootData.MyInteger);
Assert.AreEqual("0", textBlock.Text);

slider.Minimum = 10.0;

Assert.AreEqual(10.0, slider.Value);
Assert.AreEqual(10, rootData.MyInteger);
Assert.AreEqual("10", textBlock.Text);
}
}
}

0 comments on commit 900f7dd

Please sign in to comment.