Skip to content

Commit

Permalink
Fix iOS items dependency property propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jun 12, 2019
1 parent 780c43e commit e7951bb
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Infinite_Breadth.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -2229,6 +2233,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListViewResizableText.xaml.cs">
<DependentUpon>ListViewResizableText.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\ListView_Infinite_Breadth.xaml.cs">
<DependentUpon>ListView_Infinite_Breadth.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -3132,6 +3137,9 @@
<Compile Update="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\GridTestsControl\Simpletwocolumnsplitgrid.xaml.cs">
<DependentUpon>Simpletwocolumnsplitgrid.xaml</DependentUpon>
</Compile>
<Compile Update="C:\s\nv.github\uno\src\SamplesApp\UITests.Shared\Windows_UI_Xaml_Controls\ListView\ListView_DataContext_Propagation.xaml.cs">
<DependentUpon>ListView_DataContext_Propagation.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)Assets\cart.png" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.ListView.ListView_DataContext_Propagation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.ListView"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid x:Name="topGrid" DataContext="This is the datacontext">
<TextBlock x:Name="Title" Text="{Binding}"/>

<ListView
Margin="0,20,0,0"
HorizontalContentAlignment="Stretch"
SelectionMode="None"
IsItemClickEnabled="False">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<RelativePanel Margin="0,20,0,0">
<Button FontSize="12" Click="Button_Click">
<Button.Content>
<TextBlock>
<Run Text="Should be 'this is the DataContext': " />
<Run Text="{Binding Text,ElementName=Title}" />
</TextBlock>
</Button.Content>
</Button>
</RelativePanel>

</DataTemplate>
</ListView.ItemTemplate>

<x:String>Item 01</x:String>
<x:String>Item 02</x:String>
</ListView>

</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Shared.Windows_UI_Xaml_Controls.ListView
{
[SampleControlInfo("ListView", "ListView_DataContext_Propagation")]
public sealed partial class ListView_DataContext_Propagation : UserControl
{
public ListView_DataContext_Propagation()
{
this.InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
topGrid.DataContext = "Button Clicked " + sender.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
}

FrameworkElement.InitializePhaseBinding(selectorItem);
}

// Ensure the item has a parent, since it's added to the native collection view
// which does not automatically sets the parent DependencyObject.
selectorItem.SetParent(Owner?.XamlParent);
}
else if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
{
this.Log().Debug($"Reusing view at indexPath={indexPath}, previously bound to {selectorItem.DataContext}.");
Expand Down

0 comments on commit e7951bb

Please sign in to comment.