Closed LeoJHarris closed 5 years ago
@LeoJHarris I don't fully understand what you are saying.
There is no need to set the x:Name
. You just setup the binding using {Binding xxxxx}
in the XAML and in the DesignTimeData.json
you just name the XAML file and set the associated design time data.
Please take a look at the MyCoolCompany app sample provided with Gorilla. The sample has a list with the bindings and all.
Hope it helps.
@LeoHere In some of my ViewCells I dont have a binding in the XAML i.e.:
RoomViewCell.xaml:
<?xml version="1.0" encoding="UTF-8" ?>
<ViewCell
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ViewCell.View>
<StackLayout
Padding="20"
HorizontalOptions="FillAndExpand"
Orientation="Horizontal"
Spacing="20">
<Frame
x:Name="ImageColor"
Padding="0"
BackgroundColor="#EEF7D7"
CornerRadius="90"
HeightRequest="180"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="180">
<Label
x:Name="RoomNoLabel" // x:Name usage
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
TextColor="Black"
VerticalOptions="Center"
VerticalTextAlignment="Center" />
</Frame>
<StackLayout
HorizontalOptions="FillAndExpand"
Orientation="Vertical"
Spacing="10"
VerticalOptions="Center" />
</StackLayout>
</ViewCell.View>
</ViewCell>
Then in my code behind RoomViewCell.xaml.cs
private static void propertyRoomNoChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is DirtyRoomViewCell context && newValue is string name)
{
if (name.Length > _maxLength)
{
name = name.Substring(0, _maxLength);
}
context.RoomNoLabel.Text = name; // Reference x:Name
}
}
...
public static readonly BindableProperty RoomNoBindableProperty =
BindableProperty.Create(
nameof(RoomNo),
typeof(string),
typeof(DirtyRoomViewCell),
default(string),
propertyChanged: propertyRoomNoChanged);
If I am not using {Binding xxxxx}
in the xaml.cs itself but simply the x:Name then reference that, can I still do design time data?
@LeoJHarris No, Gorilla only supports previewing XAML that uses bindings. Stuff in the code behind will not be previewed.
@LeoHere Okay thanks for the response that answers my questions. Cheers
This is regarding this link: https://github.com/UXDivers/Gorilla-Player-Support/wiki/Working-with-design-time-data
I am trying to work with design time data, I have cell views comprised of an XAML and .cs file (foo.xaml foo.cs), the binding is actually just done between the View Model and the .cs file and inside the XAML file I am declaring x:Name value and referencing that in the code behind. Is there a way to send design time data directly to the ViewModel class rather then the xaml file?? How can I populate design time data in my app using gorilla player??
So instead of:
{ "fooViewCell.xaml" : [ { "Name": "John", "Age":29, "Photo":"friend_thumbnail_27.jpg" } ] ... }
it would just be:
{ "fooViewModel.cs" : [ { "Name": "John", "Age":29, "Photo":"friend_thumbnail_27.jpg" } ] ... }
I required to declare x:Name value and reference that and use the propertyChanged and other validation in the .cs file before call the x:Name value and assigning the value
Hope this makes sense..