View Issue Details

IDProjectCategoryView StatusLast Update
0000790NoesisGUIUnitypublic2018-11-23 01:31
ReporterScherub Assigned Tosfernandez  
PrioritynormalSeverityminor 
Status assignedResolutionopen 
Summary0000790: Binding to RowDefinition Height doesn't work
Description

I am trying to place an element vertically relative to a calculated item value. Just think of a horizontal level list where each item is vertically placed in a different position.

I have it working in WPF but unfortunately it doesn't work in NoesisGUI. The problem seems to be the binding of the RowGridDefinition to the GridLength property of the item. Apparently it's ignored completely.

I've also tried giving the (for the calculation) required height (so I could actually rid of the percentage) to the bound item but the property's setter is never called.

I'll now try a MultiValueConverter even if I don't know whether they're already supported by NoesisGUI.

Following the DataTemplate I've used:

[code]
<DataTemplate x:Key="LevelTemplate">
<Border x:Name="Border" Width="{Binding ActualWidth, ElementName=MainPanel, Converter={StaticResource MultiplyConverter}, ConverterParameter=0.2}"
Height="{Binding ActualHeight, ElementName=MainPanel, Converter={StaticResource MultiplyConverter}, ConverterParameter=0.45}">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="{Binding ActualHeight, ElementName=LevelItemGrid}" />
</Grid.RowDefinitions>

                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="{Binding Row1, Mode=OneWay}" />
                                <RowDefinition Height="{Binding Row2, Mode=OneWay}" />
                            </Grid.RowDefinitions>

                            <Border x:Name="Decorator" BorderBrush="Black" BorderThickness="1" />
                        </Grid>
                    </Grid>

                    <Grid x:Name="LevelItemGrid" VerticalAlignment="Top" Height="{Binding ActualHeight, ElementName=BackButton, Converter={StaticResource MultiplyConverter}, ConverterParameter=1.5}">
                        <Grid.RenderTransform>
                            <TranslateTransform Y="{Binding ActualHeight, ElementName=Decorator}" />
                        </Grid.RenderTransform>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="60*" />
                            <RowDefinition Height="20*" />
                            <RowDefinition Height="20*" />
                        </Grid.RowDefinitions>

                        <Button x:Name="Button" Grid.Row="0" Grid.RowSpan="2" IsEnabled="{Binding IsPlayable}" Style="{DynamicResource CircleButtonStyle}"
                            Command="{Binding DataContext.PlayLevelCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding .}">
                            <TextBlock Text="{Binding Name}" noesis:Text.Stroke="{DynamicResource TextStrokeBrush}" noesis:Text.StrokeThickness="{DynamicResource TextStrokeThickness}" />
                        </Button>

                        <prot:ImageViewbox Grid.Row="1" Grid.RowSpan="2" ImageBrush="{Binding Medal, Converter={StaticResource ImageKeyToImageBrushConverter}, ConverterParameter=Icons_Star_}" />
                    </Grid>
                </Grid>
            </Border>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsPlayable}" Value="False">
                    <Setter TargetName="Button" Property="BorderBrush" Value="{DynamicResource ButtonOuterStrokeDisabledBrush}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsLastPlayed}" Value="True">
                    <Setter TargetName="Button" Property="BorderBrush" Value="{DynamicResource ButtonOuterStrokeHighlightedBrush}" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

[/code]

Attached Files
Levels_Select.jpg (496,739 bytes)
PlatformAny

Activities

sfernandez

sfernandez

2016-01-07 11:29

manager   ~0003430

Hi,

Binding RowDefinition.Height works on simple scenarios, I just confirmed it. Maybe it is a problem on the layout when trying to calculate the element sizes and calculations are dependant between elements.

Could you please provide an image of what you want to accomplish? Maybe I can find an alternative while we solve the problem.

Thanks.

Scherub

Scherub

2016-01-07 13:39

reporter   ~0003437

Okay, I've uploaded an old mockup image.

sfernandez

sfernandez

2016-01-12 06:53

manager   ~0003442

Have you tried to use a TranslateTransform to move the item inside an available space?


<DataTemplate x:Key="LevelTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/> <!-- item height depends on this row height -->
<RowDefinition/> <!-- available space to move the item -->
</Grid.RowDefinitions>
<YourItem Grid.Row="0">
<YourItem.RenderTransform>
<TranslateTransform Y="{Binding OffsetY}"/>
</YourItem.RenderTransform>
...
</YourItem>
</Grid>
</DataTemplate>

Scherub

Scherub

2016-01-12 07:22

reporter   ~0003443

The problem here is that OffsetY requires a fixed value. I was trying to avoid having fixed values wherever possible and use percentages instead.

sfernandez

sfernandez

2016-01-12 07:49

manager   ~0003444

Well, OffsetY can be anything you want. This value can be something relative to screen size, item size, whatever you can imagine.

Scherub

Scherub

2016-01-12 08:38

reporter   ~0003446

Yes, you're right but for that I have to calculate the value and for that I need the available space and the percentage/alpha where it should appear.

As I said in the opening 'post' I also tried to submit the for the calculation required space to the bound level class over a property setter but that doesn't work either.

But maybe I just don't understand what you're trying to do/tell me.

sfernandez

sfernandez

2016-01-12 09:40

manager   ~0003447

For example, to get from the View the screen size you can have an attached property, set in a top element covering the screen, that subscribes to its SizeChanged event.

Knowing that value, the OffsetY property can be calculated like this:


public float OffsetY
{
get
{
return GlobalLayout.ScreenSize.Height
GlobalLayout.LevelSize.Height
// relative: [0..1]
GlobalLayout.GetOffset(Index, Parent.NumLevels); // relative: [0..1]
}
}

GetOffset provides a relative offset depending on the position of the Level in the Levels array.

Does this make any sense in your scenario? :)

Scherub

Scherub

2016-01-12 11:42

reporter   ~0003448

Well, that's not really the solution I was looking for but I guess it has to do for now.

The thing is that I already have the PC version in mind and I will use for various views different platform-dependend XAMLs but the same ViewModel and data (container) classes. So it would be much better to do these kind of things within the XAML.

But as I said, I'll do all the calculations in the data container class for now. Thanks again! :)

Issue History

Date Modified Username Field Change
2016-01-02 19:06 Scherub New Issue
2016-01-07 11:29 sfernandez Note Added: 0003430
2016-01-07 11:29 sfernandez Assigned To => sfernandez
2016-01-07 11:29 sfernandez Status new => feedback
2016-01-07 13:38 Scherub File Added: Levels_Select.jpg
2016-01-07 13:39 Scherub Note Added: 0003437
2016-01-07 13:39 Scherub Status feedback => assigned
2016-01-12 06:53 sfernandez Note Added: 0003442
2016-01-12 06:53 sfernandez Status assigned => feedback
2016-01-12 07:22 Scherub Note Added: 0003443
2016-01-12 07:22 Scherub Status feedback => assigned
2016-01-12 07:49 sfernandez Note Added: 0003444
2016-01-12 07:49 sfernandez Status assigned => feedback
2016-01-12 08:38 Scherub Note Added: 0003446
2016-01-12 08:38 Scherub Status feedback => assigned
2016-01-12 09:40 sfernandez Note Added: 0003447
2016-01-12 09:40 sfernandez Status assigned => feedback
2016-01-12 11:42 Scherub Note Added: 0003448
2016-01-12 11:42 Scherub Status feedback => assigned
2018-11-01 02:14 jsantos View Status public => private
2018-11-23 01:31 sfernandez View Status private => public
2018-11-23 01:31 sfernandez Platform => Any
2025-10-10 13:29 jsantos Category Unity3D => Unity