Heia Samahi
Topic Author
Posts: 8
Joined: 28 Mar 2018, 09:21

[Unity][Bug?] Negative Padding crashes complete UI on load

13 May 2018, 20:56

Hello,

I have a XAML Style where I want to produce an overflow text on a button.
<Setter Property="Padding" Value="-1,-10,-1,-2"/>
Works obviously great in MS Blend. But crash the UI complete in Noesis.
I've tested it so far that I can say that as soon as there's only a single minus sign in Padding, it crashes.
I hope it's a bug, how else should I create a text that overlays the button? Although there is still a way, but Padding in Noesis should be able to do that in my opinion.
If it's a bug, it's also possible to open an entry in the bug tracker, but I'm not sure.
NoesisException: '-1,-10,-1,-2' (.?AV?$Boxed@UThickness@Noesis@@@Noesis@@) is not a valid value for property 'Border.Padding'
Rethrow as NoesisException
Noesis.Error.Check () (at Assets/NoesisGUI/Plugins/API/Core/NoesisError.cs:17)
Noesis.View.Noesis_View_Create_ (HandleRef content) (at Assets/NoesisGUI/Plugins/API/Core/NoesisView.cs:402)
Noesis.View..ctor (Noesis.FrameworkElement content) (at Assets/NoesisGUI/Plugins/API/Core/NoesisView.cs:386)
NoesisView.CreateView (Noesis.FrameworkElement content) (at Assets/NoesisGUI/Plugins/NoesisView.cs:1036)
NoesisView.LoadXaml (Boolean force) (at Assets/NoesisGUI/Plugins/NoesisView.cs:340)
NoesisView.OnEnable () (at Assets/NoesisGUI/Plugins/NoesisView.cs:398)
Btw...
Removing all minus works great like this:
<Setter Property="Padding" Value="1,10,1,2"/>
Here the complete XAML if you need it.
<UserControl x:Class="CaveDigger.UI.Views.Controls.ChunkEditView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CaveDigger.UI.Views.Controls"
             xmlns:hkConverters="clr-namespace:HeiKyu.Framework.XAML.Converter;assembly=HeiKyu.Framework.XAML"
             xmlns:world="clr-namespace:CaveDigger.Scripts.World"
             mc:Ignorable="d" >
    <Grid Background="{DynamicResource Brush.Background.Sidebar}" VerticalAlignment="Top" Margin="0">
        <StackPanel>
            <Label Content="Press CTRL to avoid confirmation" Style="{DynamicResource LabelNormal}" />
            <Grid>
                <Grid.Resources>
                    <Style x:Key="ButtonPlusMinus" TargetType="{x:Type Button}">
                        <Setter Property="Width" Value="20"/>
                        <Setter Property="Height" Value="20"/>
                        <Setter Property="FontSize" Value="25"/>
                        <Setter Property="Padding" Value="-1,-10,-1,-2"/>
                    </Style>
                    <Style x:Key="ButtonPlus" TargetType="{x:Type Button}" BasedOn="{StaticResource ButtonPlusMinus}">
                        <Setter Property="Content" Value="+"/>
                        <Setter Property="Background" Value="{DynamicResource Brush.Background.LightBlue}"/>
                        <Setter Property="Command" Value="{Binding DataContext.ChunkAddCommand, ElementName=MainEditor}"/>
                    </Style>
                    <Style x:Key="ButtonMinus" TargetType="{x:Type Button}" BasedOn="{StaticResource ButtonPlusMinus}">
                        <Setter Property="Content" Value="-"/>
                        <Setter Property="Background" Value="{DynamicResource Brush.Background.LightRed}"/>
                        <Setter Property="Command" Value="{Binding DataContext.ChunkRemoveCommand, ElementName=MainEditor}"/>
                    </Style>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Label Content="{Binding DataContext.ChunkRemainingLabelZP, ElementName=MainEditor}" Grid.Column="2" Grid.Row="1" Style="{DynamicResource LabelNormal}"/>
                <Label Content="{Binding DataContext.ChunkRemainingLabelXP, ElementName=MainEditor}" Grid.Column="3" Grid.Row="2" Style="{DynamicResource LabelNormal}"/>
                <Label Content="{Binding DataContext.ChunkRemainingLabelZM, ElementName=MainEditor}" Grid.Column="2" Grid.Row="3" Style="{DynamicResource LabelNormal}"/>
                <Label Content="{Binding DataContext.ChunkRemainingLabelXM, ElementName=MainEditor}" Grid.Column="1" Grid.Row="2" Style="{DynamicResource LabelNormal}"/>
                <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="0">
                    <Button Style="{DynamicResource ButtonPlus}"  CommandParameter="{x:Static world:Orientation.ZP}" IsEnabled="{Binding DataContext.ChunkCanAddZP, ElementName=MainEditor}"/>
                    <Button Style="{DynamicResource ButtonMinus}" CommandParameter="{x:Static world:Orientation.ZP}" IsEnabled="{Binding DataContext.ChunkCanRemoveZP, ElementName=MainEditor}"/>
                </StackPanel>
                <StackPanel Orientation="Vertical" Grid.Column="2" Grid.Row="5">
                    <Button Style="{DynamicResource ButtonMinus}" CommandParameter="{x:Static world:Orientation.ZM}" IsEnabled="{Binding DataContext.ChunkCanAddZM, ElementName=MainEditor}"/>
                    <Button Style="{DynamicResource ButtonPlus}"  CommandParameter="{x:Static world:Orientation.ZM}" IsEnabled="{Binding DataContext.ChunkCanRemoveZM, ElementName=MainEditor}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="2">
                    <Button Style="{DynamicResource ButtonPlus}"  CommandParameter="{x:Static world:Orientation.XM}" IsEnabled="{Binding DataContext.ChunkCanAddXM, ElementName=MainEditor}"/>
                    <Button Style="{DynamicResource ButtonMinus}" CommandParameter="{x:Static world:Orientation.XM}" IsEnabled="{Binding DataContext.ChunkCanRemoveXM, ElementName=MainEditor}"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="2">
                    <Button Style="{DynamicResource ButtonMinus}" CommandParameter="{x:Static world:Orientation.XP}" IsEnabled="{Binding DataContext.ChunkCanAddXP, ElementName=MainEditor}"/>
                    <Button Style="{DynamicResource ButtonPlus}" CommandParameter="{x:Static world:Orientation.XP}" IsEnabled="{Binding DataContext.ChunkCanRemoveXP, ElementName=MainEditor}"/>
                </StackPanel>
            </Grid>
        </StackPanel>
    </Grid>
</UserControl>

 
User avatar
sfernandez
Site Admin
Posts: 1328
Joined: 22 Dec 2011, 19:20

Re: [Unity][Bug?] Negative Padding crashes complete UI on load

16 May 2018, 23:58

When you say that it crashes the UI completely you mean an unhandled exception that closes Unity? If that's the case, could you please create a report in our bugtracker and attach a minidump of the crash so we can analyze why is occurring, because I'm not able to get a crash.

If what you see is simply an error message in the Unity console that is intended, as negative paddings are not allowed in a Border, and our Button default template binds Control.Padding property to its template Border.Padding. Maybe we can change the template to bind to the template ContentPresenter.Margin instead to allow negative Control.Padding, so it behaves the same as WPF default styles.

Meanwhile you can do just that in your application if you need negative paddings:
<ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type ButtonBase}">
    <Border x:Name="Bg"
        Background="{TemplateBinding Background}"
        BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="{TemplateBinding BorderThickness}"
        CornerRadius="1">
        <ContentPresenter
            Margin="{TemplateBinding Padding}"
            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
    </Border>
    ...
</ControlTemplate>

Who is online

Users browsing this forum: No registered users and 14 guests