Bug 59950 - FindByName<T> Returns copy of object in UWP
Summary: FindByName<T> Returns copy of object in UWP
Status: NEEDINFO
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-04 10:53 UTC by ksemenenko
Modified: 2017-12-07 14:03 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description ksemenenko 2017-10-04 10:53:04 UTC
In UWP I found a bug, the function FindByName<T> gets a copy of the object.
The change in the object does not appear in the View.

ViewCell vc = (ViewCell)sender;
var control = vc.View.FindByName<Label>("MyLabel");
control.Text = "new test";

or 

control?.Focus();


I see in the debugger that the values have changed, but visually, nothing changes, no text, no focus, no other action.
Comment 1 Paul DiPietro [MSFT] 2017-10-11 21:26:35 UTC
FindByName<T> seems to work on UWP/2.4 with a basic Label. Does it occur only in UWP with ViewCells? Can you upload a reproduction?
Comment 2 ksemenenko 2017-10-12 08:55:29 UTC
Yes, it's in ViewCell.
it happened in the event Tapped. when I changed the style of the selected item.

xaml code

<ListView Grid.Row="0" SelectedItem="{Binding SelectedProperty}" HasUnevenRows="True" ItemsSource="{Binding Properties}"  SeparatorColor="Transparent">
	<ListView.ItemTemplate>
		<DataTemplate>
			<ViewCell Tapped="Cell_OnTapped" >
				<Grid Margin="8" RowSpacing="0" ColumnSpacing="0" x:Name="Item" >

					<Grid.RowDefinitions>
						<RowDefinition Height="*" />
						<RowDefinition Height="Auto"/>
					</Grid.RowDefinitions>
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="Auto"/>
						<ColumnDefinition Width="*"/>
					</Grid.ColumnDefinitions>

					<BoxView  Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="2" HeightRequest="55"/>
					
					<Label Text="Some Text" Grid.Row="0" Grid.Column="0" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource TextSizeLabel}" x:Name="MyLabel" 
						   IsVisible="{Binding IsRequiredProperty}" TextColor="{StaticResource Negative}" FontFamily="{StaticResource SourceSansProSemibold}"/>


					<customControls:FieldViewControl BindingContext="{Binding}" x:Name="FieldView" FontSize="{StaticResource TextSizeField}" TextColor="Black" FontFamily="{StaticResource SourceSansProRegular}"
													 Grid.Row="1"  Grid.Column="0" Grid.ColumnSpan="2" Unfocused="VisualElement_OnUnfocused" VerticalOptions="FillAndExpand" HorizontalOptions="Fill" />

				</Grid>
			</ViewCell>
		</DataTemplate>
	</ListView.ItemTemplate>
</ListView>
Comment 3 Stephane Delcroix 2017-12-07 14:03:01 UTC
FindByName<T> is in the Xamarin.Forms.Internals namespace. Use it if it works for you, but do not complain if it does not :)

Note You need to log in before you can comment on or make changes to this bug.